Bug 1539027 - Use a hopefully faster rounding for float -> app units conversion. r=dholbert
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 27 Mar 2019 16:17:55 +0000
changeset 466390 fb7fb6f72fb1a0b907e1d25f59026fe1c7cfdf16
parent 466389 06b200ff82e61d99e47d7fbff55262dff8491c6c
child 466391 8b08bbc890d4e279f35015e4c9eec1f39fa66f9e
push id35768
push useropoprus@mozilla.com
push dateThu, 28 Mar 2019 09:55:54 +0000
treeherdermozilla-central@c045dd97faf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1539027
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1539027 - Use a hopefully faster rounding for float -> app units conversion. r=dholbert LLVM doesn't manage to use any fast code for froundf, so use NSToIntRound instead, which is probably what we should be using anyway for consistency. Differential Revision: https://phabricator.services.mozilla.com/D25049
layout/style/nsStyleCoord.h
--- a/layout/style/nsStyleCoord.h
+++ b/layout/style/nsStyleCoord.h
@@ -45,31 +45,31 @@ using NonNegativeLengthPercentage = Styl
 using NonNegativeLengthPercentageOrAuto =
     StyleNonNegativeLengthPercentageOrAuto;
 using BorderRadius = StyleBorderRadius;
 
 bool StyleCSSPixelLength::IsZero() const { return _0 == 0.0f; }
 
 nscoord StyleCSSPixelLength::ToAppUnits() const {
   // We want to resolve the length part of the calc() expression rounding 0.5
-  // away from zero, instead of the default behavior of NSToCoordRoundWithClamp
-  // which is floor(x + 0.5).
+  // away from zero, instead of the default behavior of
+  // NSToCoordRound{,WithClamp} which do floor(x + 0.5).
   //
   // This is what the rust code in the app_units crate does, and not doing this
   // would regress bug 1323735, for example.
   //
   // FIXME(emilio, bug 1528114): Probably we should do something smarter.
   float length = _0 * float(mozilla::AppUnitsPerCSSPixel());
   if (length >= nscoord_MAX) {
     return nscoord_MAX;
   }
   if (length <= nscoord_MIN) {
     return nscoord_MIN;
   }
-  return roundf(length);
+  return NSToIntRound(length);
 }
 
 constexpr LengthPercentage LengthPercentage::Zero() {
   return {{0.}, {0.}, StyleAllowedNumericType::All, false, false};
 }
 
 LengthPercentage LengthPercentage::FromPixels(CSSCoord aCoord) {
   return {{aCoord}, {0.}, StyleAllowedNumericType::All, false, false};