clampTo(): do not convert the input to double when dealing with integers
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2019 09:46:36 +0000 (09:46 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2019 09:46:36 +0000 (09:46 +0000)
commit19d83db59b0772820acc443eeb3d8592b645f631
tree8256e1ae21b01ac84811d420028aba9fb1389e5d
parenta4c28cb74f7a3f436cb24e4491180f7ee9c607c9
clampTo(): do not convert the input to double when dealing with integers
https://bugs.webkit.org/show_bug.cgi?id=194263
<rdar://problem/47692312>

Reviewed by Darin Adler.

Source/WebCore:

Make the calls to clampTo<float>() unambiguous.

* page/FrameView.cpp:
(WebCore::FrameView::computeUpdatedLayoutViewportRect):
* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::setOpacity):
(WebCore::RenderStyle::setShapeImageThreshold):

Source/WTF:

Previously, every use of clampTo() was converting the input to double,
doing the comparison in double, then casting back to whatever type was needed.

In many case, that was very wasteful. WebKit has many cases of clampTo() with
the same type as input/output, or with integer types of different size/sign.

This patch adds a few versions of clampTo() for the common cases seen in WebKit.
In each case, I tried to minimize the amount of conversion needed at runtime.

* wtf/MathExtras.h:
(clampTo):

Tools:

* TestWebKitAPI/Tests/WTF/MathExtras.cpp:
(TestWebKitAPI::testClampFloatingPointToFloatingPoint):
(TestWebKitAPI::testClampFloatingPointToInteger):
(TestWebKitAPI::testClampSameSignIntegers):
(TestWebKitAPI::testClampUnsignedToSigned):
(TestWebKitAPI::testClampSignedToUnsigned):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241192 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WTF/ChangeLog
Source/WTF/wtf/MathExtras.h
Source/WebCore/ChangeLog
Source/WebCore/page/FrameView.cpp
Source/WebCore/rendering/style/RenderStyle.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/MathExtras.cpp