Closed
Bug 1203350
Opened 9 years ago
Closed 9 years ago
Unify certain arithmetic operators in TimeStamp
Categories
(Core :: mozglue, defect)
Core
mozglue
Tracking
()
RESOLVED
FIXED
mozilla43
Tracking | Status | |
---|---|---|
firefox43 | --- | fixed |
People
(Reporter: birtles, Assigned: birtles)
References
Details
Attachments
(1 file)
1.68 KB,
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
Follow-up from bug 1202556, we should remove duplicate code between operator+ and operator+= by writing one in terms of the other. Likewise for subtraction.
Assignee | ||
Comment 1•9 years ago
|
||
Attachment #8658995 -
Flags: review?(nfroyd)
Updated•9 years ago
|
Attachment #8658995 -
Flags: review?(nfroyd) → review+
Comment 2•9 years ago
|
||
Thank you!
Comment 3•9 years ago
|
||
Comment on attachment 8658995 [details] [diff] [review] Unify arithmetic operators in TimeStamp Review of attachment 8658995 [details] [diff] [review]: ----------------------------------------------------------------- One minor thing I thought of after the fact: ::: mozglue/misc/TimeStamp.h @@ +491,5 @@ > > TimeStamp operator+(const TimeDuration& aOther) const > { > + TimeStamp result = *this; > + return result += aOther; Actually, can you write this as: result += aOther; return result; so the compiler's named-value return optimization kicks in? I'm unsure of whether the right thing would happen with trying to copy-constructor the returned reference from operator+=. @@ +496,5 @@ > } > TimeStamp operator-(const TimeDuration& aOther) const > { > + TimeStamp result = *this; > + return result -= aOther; Likewise here.
Assignee | ||
Comment 4•9 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #3) > Actually, can you write this as: > > result += aOther; > return result; > > so the compiler's named-value return optimization kicks in? I'm unsure of > whether the right thing would happen with trying to copy-constructor the > returned reference from operator+=. Yeah, I was wondering the exact same thing. I did some digging around to see if compiler's would apply RVO if I rolled up the two statements and I got the impression from MSVC's docs that it probably would (it only called out returning separately-named objects as problematic) but better to be safe.
Comment 6•9 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/b2d47f9818ce
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla43
You need to log in
before you can comment on or make changes to this bug.
Description
•