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

All equals methods should first check for reference equality... #84

Closed
mramato opened this issue Jun 27, 2012 · 4 comments
Closed

All equals methods should first check for reference equality... #84

mramato opened this issue Jun 27, 2012 · 4 comments
Labels

Comments

@mramato
Copy link
Contributor

mramato commented Jun 27, 2012

While the performance improvement will probably be negligible, it's just good practice. Static instances should also handle the case where both parameters are undefined and prototype instances should check if the passed in object is undefined.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 27, 2012

I know it is good practice in C++ when implementing operator=, but why is it always good practice in JavaScript, for say Cartesian2? Of course, I'm in agreement for Matrix4, etc.

@mramato
Copy link
Contributor Author

mramato commented Jun 27, 2012

I think it's the same reason you would want to do it on Matrix4. If two Cartesian2 values are identical, then it requires 4 property look-ups in order to determine equality. So doing reference equality first is faster (plus the reference equality check itself has no performance impact).

It also makes the code all follow the same pattern. I heard someone say once that "consistency is clean".

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 27, 2012

Right, I was thinking about saying do it for consistency too.

So it's an optimization - assuming that we often compare objects whose references are the same. Why doesn't the reference equality have a performance impact? My C++ answer is because the branch predictor always gets it right, but is there a JavaScript reason?

I actually don't care all that much one way or the other, I just want to confirm that we thought through it.

mramato added a commit that referenced this issue Jul 13, 2012
1. All prototype functions now have static equivalents.
2. All functions now do proper error checking.
3. All functions no longer require Cartesian3 instances and instead will work with any object that has an x, y, and z properties.
4. All functions that produce a Cartesian3 now take an optional result parameter.
5. Code coverage for Cartesian3 is now 100%
6. Remove a few unused functions.
7. Add several functions to Cartesian2 that already existed on Cartesian3 (everything but cross).

These changes are related to issues #71, #84, #86 (those issues will remain open until we address them for every Core type).
mramato added a commit that referenced this issue Jul 13, 2012
1. All prototype functions now have static equivalents.
2. All functions now do proper error checking.
3. All functions no longer require Cartesian4 instances and instead will work with any object that has an x, y, z, and w properties.
4. All functions that produce a Cartesian4 now take an optional result parameter.
5. Code coverage for Cartesian4 is now 100%
6. Remove Math.angleBetween because it already exists on the Cartesian functions.

These changes are related to issues #71, #84, #86 (those issues will remain open until we address them for every Core type).
@mramato
Copy link
Contributor Author

mramato commented Oct 22, 2012

I'm fine with calling this cleanup "done" There may be a few straggling cases that we'll uncover as we continue to do clean-up, but all of the "important" core types certainly have the reference check.

@mramato mramato closed this as completed Oct 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants