Use TimeDuration::Zero() where appropriate
Categories
(Core :: mozglue, task)
Tracking
()
People
(Reporter: jlink, Assigned: alex.you0825, Mentored)
References
Details
(Keywords: good-first-bug, Whiteboard: [lang=c++])
Attachments
(1 external file)
Filing as a good first bug to learn workflows.
TimeDuration::Zero() is a constexpr factory that yields a zero-length duration
directly. Eleven call sites instead build a zero duration by calling
TimeDuration::FromSeconds(0) or TimeDuration::FromMilliseconds(0), which asks
the platform to convert a count of units into a tick count. On platforms whose
tick rate is only known at run time (Windows and macOS) that conversion is an
out-of-line call into mozglue, which multiplies zero by the ticks-per-unit and
returns zero. Zero() needs no call at all; it compiles to storing an immediate.
Replace those calls with TimeDuration::Zero(). The affected files, with the
number of call sites in each:
dom/media/MediaManager.cpp 1
dom/media/encoder/VP8TrackEncoder.cpp 2
dom/vr/VRDisplay.cpp 1
gfx/layers/wr/WebRenderBridgeParent.cpp 1
gfx/thebes/SoftwareVsyncSource.cpp 1
gfx/thebes/gfxWindowsPlatform.cpp 1
js/src/gc/Statistics.cpp 1
layout/base/nsRefreshDriver.cpp 1
mozglue/misc/ConditionVariable_posix.cpp 2
You can find them yourself with:
grep -rnE "TimeDuration::From(Seconds|Milliseconds|Microseconds|Nanoseconds)(0(.0*)?f?)" --include=.cpp --include=.h .
Please do NOT change xpcom/tests/gtest/TestTimeStamp.cpp. The FromNanoseconds(0)
calls there exist to check that the factories accept zero, so replacing them
would delete the coverage. Call sites in the other gtest files that the grep
finds (TestVideoFrameConverter.cpp, TestPositionState.cpp, APZTestCommon.h,
testSliceBudget.cpp) are optional: converting them is fine but not required.
Link to the code:
https://searchfox.org/firefox-main/source/mozglue/misc/TimeStamp.h
To verify the fix:
./mach build binaries
./mach lint -l clang-format <the files you changed>
Behaviour is unchanged. FromSeconds(0) and FromMilliseconds(0) both produce a
duration of zero ticks, which is exactly what Zero() returns, so no test should
change.
One thing to expect: the patch spans several modules, so Phabricator will want
a reviewer from each. That is normal for a mechanical cleanup like this and is
not a sign anything is wrong.
Tutorial to contribute:
https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
https://firefox-source-docs.mozilla.org/contributing/stack_quickref.html
Please don't ask for the bug to be assigned. It will be automatically assigned to the first patch.
Updated•5 days ago
|
Description
•