Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance increase #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

AdamFrisby
Copy link

Reduces memory allocations and slightly increases performance

Reduces memory allocations and slightly increases performance
{
if (SubInstance._sensor != null && Translation == null)
Translation = SubInstance._sensor.Translation;

float sensitivity = Application.isPlaying ? Settings.PlayTransSens : Settings.TransSens[Settings.CurrentGear];
return (SubInstance._sensor == null ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing SubInstance._sensor == null twice. Can be put at the top of the method with an early return.

if (SubInstance._sensor != null && Rotation == null)
Rotation = SubInstance._sensor.Rotation;

float sensitivity = Application.isPlaying ? Settings.PlayRotSens : Settings.RotSens;
return (SubInstance._sensor == null ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, testing SubInstance._sensor == null twice. Same solution.

public override Vector3 GetTranslation() {
public override Vector3 GetTranslation()
{
if (SubInstance._sensor != null && Translation == null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Match the indent of the rest of this method, especially since you're not using { } (which I would highly recommend using).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a real-world example of why you should really use curly braces (TLDR: major security failure in Apple's SSL).
https://blog.codecentric.de/en/2014/02/curly-braces/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants