-
Notifications
You must be signed in to change notification settings - Fork 51
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
base: master
Are you sure you want to change the base?
Conversation
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 ? |
There was a problem hiding this comment.
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 ? |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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/
Reduces memory allocations and slightly increases performance