-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Introduce static get and set functions for ControlObject #28
Conversation
LGTM -- it may be useful to provide a default value or a bool* that is set if the control existed or not but whoever needs that first can add it. |
Thank you for review! |
Introduce static get and set functions for ControlObject
// Sets the ControlObject value | ||
void set(const double& value); | ||
// Instantly sets the value of the ControlObject | ||
static void set(const ConfigKey& key, const double& value); |
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.
Alright, I know this has already been merged -- but what reasoning exists for taking a constant ref to a double instead of just passing a double?
For all the stylistic nits I see being picked on in github mail, this seems exceptionally odd to go uncommented.
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.
I don't see any style issues. The & is in the right place :P.
Doubles are 64-bit so on a 32-bit platform passing by reference is slightly less data to push on the stack.
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.
That might be my favourite comment ever, Bill. 👍
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.
It is not worth talking about, but since I am an embedded developer I wanted to know. So I have written a test with an interesting results:
- When passing a double or a double& to a function with compatible parameters there is no difference because the parameters are not touched.
- When passing a double to a function with incompatible parameters it requires two more instructions then a double& on a 32bit target. On a 64 bit target it is the same.
- Making a double from a double& takes at least on instruction more for fetching the address of the defence on both architectures.
- passing a double& in one call and the passing a double in a sub call takes 3 instructions more than passing double in both calls, on a both targets. On a 64 bit system both versions are two instructions shorter.
Conclusion:
There is no general answer what is best, but we should avoid converting between double and double&.
Fix typo: "comment line" -> "command line"
This is a next step to get rid of the double hash in CO and COP