quote:Original post by gspdriver
Use the second assignment operator...ALWAYS!!!
Why? Because it is more efficient.
Nope. See above comment about spurious temporary objects being constructed.
quote:
You need to add more thing into your assignment operator.
You need to check if you are copying to the same location.
Checking for self-assignment for a simple class like this is counter-productive. Self-assignment in a 3d vector class is unlikely to occur that frequently, so its likely waste cycles for evaluating the conditional. Not only that, but due to branch prediction, you''re likely going to cause a nice pipeline bubble even when you do skip the assignments, so you won''t gain a cycles. There''s also the fact that you''ll be polluting the branch prediction cache, causing other branch predicitons to be less accurate; thus reducing the overall performance of your application.