Title: [138952] trunk
Revision
138952
Author
jchaffr...@webkit.org
Date
2013-01-07 09:25:37 -0800 (Mon, 07 Jan 2013)

Log Message

Support size_t multiplication and division operators on LayoutUnit
https://bugs.webkit.org/show_bug.cgi?id=83848

Reviewed by Emil A Eklund.

Source/WebCore:

Per Darin's suggestion, adding a version of the operator for most unsigned types (excluding
only unsigned char). This should automatically cover size_t as it should be one of these.

Test: TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp

* platform/LayoutUnit.h:
(WebCore::LayoutUnit::LayoutUnit):
(WebCore::operator*):
(WebCore::operator/):
Added the operators and (possibly saturating) constructors for unsigned short, unsigned long,
unsigned long long.

Tools:

* TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp:
Added some simple tests for the new operators using size_t.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (138951 => 138952)


--- trunk/Source/WebCore/ChangeLog	2013-01-07 17:15:19 UTC (rev 138951)
+++ trunk/Source/WebCore/ChangeLog	2013-01-07 17:25:37 UTC (rev 138952)
@@ -1,3 +1,22 @@
+2013-01-07  Julien Chaffraix  <jchaffr...@webkit.org>
+
+        Support size_t multiplication and division operators on LayoutUnit
+        https://bugs.webkit.org/show_bug.cgi?id=83848
+
+        Reviewed by Emil A Eklund.
+
+        Per Darin's suggestion, adding a version of the operator for most unsigned types (excluding
+        only unsigned char). This should automatically cover size_t as it should be one of these.
+
+        Test: TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp
+
+        * platform/LayoutUnit.h:
+        (WebCore::LayoutUnit::LayoutUnit):
+        (WebCore::operator*):
+        (WebCore::operator/):
+        Added the operators and (possibly saturating) constructors for unsigned short, unsigned long,
+        unsigned long long.
+
 2013-01-07  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r138944.

Modified: trunk/Source/WebCore/platform/LayoutUnit.h (138951 => 138952)


--- trunk/Source/WebCore/platform/LayoutUnit.h	2013-01-07 17:15:19 UTC (rev 138951)
+++ trunk/Source/WebCore/platform/LayoutUnit.h	2013-01-07 17:25:37 UTC (rev 138952)
@@ -66,15 +66,29 @@
 
 class LayoutUnit {
 public:
-    // FIXME: Ideally we would have size_t versions of the constructor and operators.
-    // However due to compiler and platform differences adding those are non-trivial.
-    // See https://bugs.webkit.org/show_bug.cgi?id=83848 for details.
-    
     LayoutUnit() : m_value(0) { }
 #if ENABLE(SUBPIXEL_LAYOUT)
     LayoutUnit(int value) { setValue(value); }
     LayoutUnit(unsigned short value) { setValue(value); }
     LayoutUnit(unsigned value) { setValue(value); }
+    LayoutUnit(unsigned long value)
+    {
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+        m_value = clampTo<int>(value * kEffectiveFixedPointDenominator);
+#else
+        REPORT_OVERFLOW(isInBounds(static_cast<unsigned>(value)));
+        m_value = value * kEffectiveFixedPointDenominator;
+#endif
+    }
+    LayoutUnit(unsigned long long value)
+    {
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+        m_value = clampTo<int>(value * kEffectiveFixedPointDenominator);
+#else
+        REPORT_OVERFLOW(isInBounds(static_cast<unsigned>(value)));
+        m_value = value * kEffectiveFixedPointDenominator;
+#endif
+    }
     LayoutUnit(float value)
     {
 #if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
@@ -97,6 +111,8 @@
     LayoutUnit(int value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; }
     LayoutUnit(unsigned short value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; }
     LayoutUnit(unsigned value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; }
+    LayoutUnit(unsigned long long value) { REPORT_OVERFLOW(isInBounds(static_cast<unsigned>(value))); m_value = value; }
+    LayoutUnit(unsigned long value) { REPORT_OVERFLOW(isInBounds(static_cast<unsigned>(value))); m_value = value; }
     LayoutUnit(float value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; }
     LayoutUnit(double value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; }
 #endif
@@ -537,16 +553,46 @@
     return a * LayoutUnit(b);
 }
 
+inline LayoutUnit operator*(const LayoutUnit& a, unsigned short b)
+{
+    return a * LayoutUnit(b);
+}
+
 inline LayoutUnit operator*(const LayoutUnit& a, unsigned b)
 {
     return a * LayoutUnit(b);
 }
 
+inline LayoutUnit operator*(const LayoutUnit& a, unsigned long b)
+{
+    return a * LayoutUnit(b);
+}
+
+inline LayoutUnit operator*(const LayoutUnit& a, unsigned long long b)
+{
+    return a * LayoutUnit(b);
+}
+
+inline LayoutUnit operator*(unsigned short a, const LayoutUnit& b)
+{
+    return LayoutUnit(a) * b;
+}
+
 inline LayoutUnit operator*(unsigned a, const LayoutUnit& b)
 {
     return LayoutUnit(a) * b;
 }
 
+inline LayoutUnit operator*(unsigned long a, const LayoutUnit& b)
+{
+    return LayoutUnit(a) * b;
+}
+
+inline LayoutUnit operator*(unsigned long long a, const LayoutUnit& b)
+{
+    return LayoutUnit(a) * b;
+}
+
 inline LayoutUnit operator*(const int a, const LayoutUnit& b)
 {
     return LayoutUnit(a) * b;
@@ -593,11 +639,26 @@
     return a / LayoutUnit(b);
 }
 
+inline LayoutUnit operator/(const LayoutUnit& a, unsigned short b)
+{
+    return a / LayoutUnit(b);
+}
+
 inline LayoutUnit operator/(const LayoutUnit& a, unsigned b)
 {
     return a / LayoutUnit(b);
 }
 
+inline LayoutUnit operator/(const LayoutUnit& a, unsigned long b)
+{
+    return a / LayoutUnit(b);
+}
+
+inline LayoutUnit operator/(const LayoutUnit& a, unsigned long long b)
+{
+    return a / LayoutUnit(b);
+}
+
 inline float operator/(const float a, const LayoutUnit& b)
 {
     return a / b.toFloat();
@@ -613,11 +674,26 @@
     return LayoutUnit(a) / b;
 }
 
+inline LayoutUnit operator/(unsigned short a, const LayoutUnit& b)
+{
+    return LayoutUnit(a) / b;
+}
+
 inline LayoutUnit operator/(unsigned a, const LayoutUnit& b)
 {
     return LayoutUnit(a) / b;
 }
 
+inline LayoutUnit operator/(unsigned long a, const LayoutUnit& b)
+{
+    return LayoutUnit(a) / b;
+}
+
+inline LayoutUnit operator/(unsigned long long a, const LayoutUnit& b)
+{
+    return LayoutUnit(a) / b;
+}
+
 inline LayoutUnit operator+(const LayoutUnit& a, const LayoutUnit& b)
 {
     LayoutUnit returnVal;

Modified: trunk/Tools/ChangeLog (138951 => 138952)


--- trunk/Tools/ChangeLog	2013-01-07 17:15:19 UTC (rev 138951)
+++ trunk/Tools/ChangeLog	2013-01-07 17:25:37 UTC (rev 138952)
@@ -1,3 +1,13 @@
+2013-01-07  Julien Chaffraix  <jchaffr...@webkit.org>
+
+        Support size_t multiplication and division operators on LayoutUnit
+        https://bugs.webkit.org/show_bug.cgi?id=83848
+
+        Reviewed by Emil A Eklund.
+
+        * TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp:
+        Added some simple tests for the new operators using size_t.
+
 2013-01-07  Csaba Osztrogonác  <o...@webkit.org>
 
         [Qt] run-webkit-tests cleanup for parallel NRWT

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp (138951 => 138952)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp	2013-01-07 17:15:19 UTC (rev 138951)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp	2013-01-07 17:25:37 UTC (rev 138952)
@@ -146,12 +146,22 @@
     ASSERT_EQ((LayoutUnit(100) * LayoutUnit(3.33)).round(), 333);
     ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(3.33)).round(), -333);
     ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(-3.33)).round(), 333);
-    
+
+    size_t aHundredSizeT = 100;
+    ASSERT_EQ((LayoutUnit(aHundredSizeT) * LayoutUnit(1)).toInt(), 100);
+    ASSERT_EQ((aHundredSizeT * LayoutUnit(4)).toInt(), 400);
+    ASSERT_EQ((LayoutUnit(4) * aHundredSizeT).toInt(), 400);
+
     int quarterMax = intMaxForLayoutUnit / 4;
     ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(2)).toInt(), quarterMax * 2);
     ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(3)).toInt(), quarterMax * 3);
     ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(4)).toInt(), quarterMax * 4);
     ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(5)).toInt(), intMaxForLayoutUnit);
+
+    size_t overflowIntSizeT = intMaxForLayoutUnit * 4;
+    ASSERT_EQ((LayoutUnit(overflowIntSizeT) * LayoutUnit(2)).toInt(), intMaxForLayoutUnit);
+    ASSERT_EQ((overflowIntSizeT * LayoutUnit(4)).toInt(), intMaxForLayoutUnit);
+    ASSERT_EQ((LayoutUnit(4) * overflowIntSizeT).toInt(), intMaxForLayoutUnit);
 }
 
 TEST(WebCoreLayoutUnit, LayoutUnitDivision)
@@ -183,6 +193,11 @@
     ASSERT_FLOAT_EQ((LayoutUnit(-1) / LayoutUnit(-2)).toFloat(), 0.5f);
     ASSERT_FLOAT_EQ((LayoutUnit(-0.5) / LayoutUnit(-2)).toFloat(), 0.25f);
     
+    size_t aHundredSizeT = 100;
+    ASSERT_EQ((LayoutUnit(aHundredSizeT) / LayoutUnit(2)).toInt(), 50);
+    ASSERT_EQ((aHundredSizeT / LayoutUnit(4)).toInt(), 25);
+    ASSERT_EQ((LayoutUnit(400) / aHundredSizeT).toInt(), 4);
+
     ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) / LayoutUnit(2)).toInt(), intMaxForLayoutUnit / 2);
     ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) / LayoutUnit(0.5)).toInt(), intMaxForLayoutUnit);
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to