From 2c084a33fda83d055e897a29bc772a9d46878d9c Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Fri, 31 May 2019 22:10:59 +0000 Subject: [PATCH] Bug 1555511 Part 2: Remove a float division in MVM::ScaleZoomWithDisplayWidth. r=botond This is a drive-by fix to turn a division into a multiplication. It also is more correct in that the existing code attempts a divide-by-zero if aNewViewport.width is zero. The updated code will instead return a zoom of zero in such a case. Differential Revision: https://phabricator.services.mozilla.com/D32909 --HG-- extra : moz-landing-system : lando --- layout/base/MobileViewportManager.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/layout/base/MobileViewportManager.cpp b/layout/base/MobileViewportManager.cpp index dabf6733ab7a..1010cd3ad1e0 100644 --- a/layout/base/MobileViewportManager.cpp +++ b/layout/base/MobileViewportManager.cpp @@ -184,13 +184,13 @@ CSSToScreenScale MobileViewportManager::ClampZoom( CSSToScreenScale MobileViewportManager::ScaleZoomWithDisplayWidth( const CSSToScreenScale& aZoom, const float& aDisplayWidthChangeRatio, const CSSSize& aNewViewport, const CSSSize& aOldViewport) { - float cssViewportChangeRatio = (aOldViewport.width == 0) - ? 1.0f - : aNewViewport.width / aOldViewport.width; - CSSToScreenScale newZoom(aZoom.scale * aDisplayWidthChangeRatio / - cssViewportChangeRatio); - MVM_LOG("%p: Old zoom was %f, changed by %f/%f to %f\n", this, aZoom.scale, - aDisplayWidthChangeRatio, cssViewportChangeRatio, newZoom.scale); + float inverseCssWidthChangeRatio = + (aNewViewport.width == 0) ? 1.0f + : aOldViewport.width / aNewViewport.width; + CSSToScreenScale newZoom(aZoom.scale * aDisplayWidthChangeRatio * + inverseCssWidthChangeRatio); + MVM_LOG("%p: Old zoom was %f, changed by %f * %f to %f\n", this, aZoom.scale, + aDisplayWidthChangeRatio, inverseCssWidthChangeRatio, newZoom.scale); return newZoom; }