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

Introduce static get and set functions for ControlObject #28

Merged
merged 1 commit into from
Jun 28, 2013

Conversation

daschuer
Copy link
Member

This is a next step to get rid of the double hash in CO and COP

@rryan
Copy link
Member

rryan commented Jun 28, 2013

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.

@daschuer
Copy link
Member Author

Thank you for review!

daschuer added a commit that referenced this pull request Jun 28, 2013
Introduce static get and set functions for ControlObject
@daschuer daschuer merged commit 82c4a75 into mixxxdj:master Jun 28, 2013
// 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);
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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

Copy link
Member Author

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:

  1. When passing a double or a double& to a function with compatible parameters there is no difference because the parameters are not touched.
  2. 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.
  3. Making a double from a double& takes at least on instruction more for fetching the address of the defence on both architectures.
  4. 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&.

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.

4 participants