Skip to content

Performance increase#19

Open
AdamFrisby wants to merge 1 commit into
PatHightree:masterfrom
AdamFrisby:patch-1
Open

Performance increase#19
AdamFrisby wants to merge 1 commit into
PatHightree:masterfrom
AdamFrisby:patch-1

Conversation

@AdamFrisby
Copy link
Copy Markdown

Reduces memory allocations and slightly increases performance

Reduces memory allocations and slightly increases performance
Translation = SubInstance._sensor.Translation;

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

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.

Rotation = SubInstance._sensor.Rotation;

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

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)
Copy link
Copy Markdown

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).

Copy link
Copy Markdown

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