Closed
Bug 1107351
Opened 10 years ago
Closed 10 years ago
Simplify AnimationPlayer::GetCurrentTime() with early-returns
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla37
People
(Reporter: dholbert, Assigned: dholbert)
References
Details
Attachments
(1 file, 1 obsolete file)
977 bytes,
patch
|
birtles
:
review+
|
Details | Diff | Splinter Review |
Noticed while reviewing bug 1104424: The method AnimationPlayer::GetCurrentTime() could be made a bit more skimmable if it used early-returns instead of its current if/else + 'result' structure. Filing this bug on doing that cleanup.
Assignee | ||
Comment 1•10 years ago
|
||
This ended up being maybe a bit more complicated, but that's partly because I've made it more efficient than the existing code, by preventing a call to mTimeline->GetCurrentTime() if we don't actually need it (if mStartTime is null). Brian, what do you think?
Attachment #8531801 -
Flags: review?(birtles)
Comment 2•10 years ago
|
||
(In reply to Daniel Holbert [:dholbert] from comment #1) > Created attachment 8531801 [details] [diff] [review] > fix v1 > > This ended up being maybe a bit more complicated, but that's partly because > I've made it more efficient than the existing code, by preventing a call to > mTimeline->GetCurrentTime() if we don't actually need it (if mStartTime is > null). > > Brian, what do you think? I think avoiding the call to GetCurrentTime is really nice. It's a shame we lose RVO with this though. How about: >Nullable<TimeDuration> >AnimationPlayer::GetCurrentTime() const >{ > Nullable<TimeDuration> result; > > if (!mHoldTime.IsNull()) { > result = mHoldTime; > return result; > } > > if (!mStartTime.IsNull()) { > Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTime(); > if (!timelineTime.IsNull()) { > result = timelineTime.Value() - mStartTime.Value(); > } > } > > return result; >} We could avoid the nested branches like so: >Nullable<TimeDuration> >AnimationPlayer::GetCurrentTime() const >{ > Nullable<TimeDuration> result; > > if (!mHoldTime.IsNull()) { > result = mHoldTime; > return result; > } > > if (mStartTime.IsNull()) { > return result; > } > > Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTime(); > if (timelineTime.IsNull()) { > return result; > } > > result = timelineTime.Value() - mStartTime.Value(); > return result; >} I prefer the first, shorter version however.
Depends on: 1104424
Assignee | ||
Comment 3•10 years ago
|
||
Ah, right -- I wasn't thinking about RVO. I'm actually not sure RVO does much for us here; from a quick skim, it looks like TimeDuration only has one member-var -- "int64_t mValue" -- so copying the return value into the caller's local variable isn't particularly expensive. Though I suppose on a 32-bit system, it helps a bit. The first, shorter version looks good to me -- I'll rewrite to match that & repost. Thanks!
Assignee | ||
Updated•10 years ago
|
Flags: needinfo?(dholbert)
Assignee | ||
Comment 4•10 years ago
|
||
Here's the updated patch. This really only changes two things w.r.t. the existing code: - adds 1 early-return to convert "if/else" into just "if" - Promotes the !mStartTime.IsNull() check to avoid an unneeded GetCurrentTime call.
Attachment #8531801 -
Attachment is obsolete: true
Attachment #8531801 -
Flags: review?(birtles)
Flags: needinfo?(dholbert)
Attachment #8531871 -
Flags: review?(birtles)
Comment 5•10 years ago
|
||
Comment on attachment 8531871 [details] [diff] [review] fix v2 Review of attachment 8531871 [details] [diff] [review]: ----------------------------------------------------------------- Looks great. Thanks Daniel!
Attachment #8531871 -
Flags: review?(birtles) → review+
Assignee | ||
Comment 6•10 years ago
|
||
Thanks! Landed: https://hg.mozilla.org/integration/mozilla-inbound/rev/69b7229fa7a0
Flags: in-testsuite-
Comment 7•10 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/69b7229fa7a0
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla37
Updated•5 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•