Ignore:
Timestamp:
May 23, 2011, 3:33:39 PM (14 years ago)
Author:
[email protected]
Message:

2011-05-23 Matthew Delaney <[email protected]>

Reviewed by Simon Fraser.

Remove safeFloatToInt() in FloatRect.cpp and replace with working version of clampToInteger()
https://bugs.webkit.org/show_bug.cgi?id=58216

  • wtf/MathExtras.h: (clampToInteger): (clampToPositiveInteger):

2011-05-23 Matthew Delaney <[email protected]>

Reviewed by Simon Fraser.

Remove safeFloatToInt() in FloatRect.cpp and replace with working version of clampToInteger()
https://bugs.webkit.org/show_bug.cgi?id=58216

No new tests. The SVG tests mask-excessive-malloc.svg and pattern-excessive-malloc.svg exercise this code path.

  • platform/graphics/FloatRect.cpp: (WebCore::enclosingIntRect):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wtf/MathExtras.h

    r83179 r87103  
    221221}
    222222
    223 inline int clampToInteger(float d)
    224 {
    225     const float minIntAsFloat = static_cast<float>(std::numeric_limits<int>::min());
    226     const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max());
    227     return static_cast<int>(std::max(std::min(d, maxIntAsFloat), minIntAsFloat));
    228 }
    229 
    230 inline int clampToPositiveInteger(float d)
    231 {
    232     const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max());
    233     return static_cast<int>(std::max<float>(std::min(d, maxIntAsFloat), 0));
     223inline int clampToInteger(float x)
     224{
     225    static const int s_intMax = std::numeric_limits<int>::max();
     226    static const int s_intMin = std::numeric_limits<int>::min();
     227   
     228    if (x >= static_cast<float>(s_intMax))
     229        return s_intMax;
     230    if (x < static_cast<float>(s_intMin))
     231        return s_intMin;
     232    return static_cast<int>(x);
     233}
     234
     235inline int clampToPositiveInteger(float x)
     236{
     237    static const int s_intMax = std::numeric_limits<int>::max();
     238   
     239    if (x >= static_cast<float>(s_intMax))
     240        return s_intMax;
     241    if (x < 0)
     242        return 0;
     243    return static_cast<int>(x);
    234244}
    235245
Note: See TracChangeset for help on using the changeset viewer.