Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: Source/JavaScriptCore/wtf/MathExtras.h

Issue 7155005: Merge 87103 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/742/
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/WebCore/platform/graphics/FloatRect.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/JavaScriptCore/wtf/MathExtras.h
===================================================================
--- Source/JavaScriptCore/wtf/MathExtras.h (revision 88844)
+++ Source/JavaScriptCore/wtf/MathExtras.h (working copy)
@@ -220,17 +220,27 @@
return static_cast<int>(std::max<double>(std::min(d, maxIntAsDouble), 0));
}
-inline int clampToInteger(float d)
+inline int clampToInteger(float x)
{
- const float minIntAsFloat = static_cast<float>(std::numeric_limits<int>::min());
- const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max());
- return static_cast<int>(std::max(std::min(d, maxIntAsFloat), minIntAsFloat));
+ static const int s_intMax = std::numeric_limits<int>::max();
+ static const int s_intMin = std::numeric_limits<int>::min();
+
+ if (x >= static_cast<float>(s_intMax))
+ return s_intMax;
+ if (x < static_cast<float>(s_intMin))
+ return s_intMin;
+ return static_cast<int>(x);
}
-inline int clampToPositiveInteger(float d)
+inline int clampToPositiveInteger(float x)
{
- const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max());
- return static_cast<int>(std::max<float>(std::min(d, maxIntAsFloat), 0));
+ static const int s_intMax = std::numeric_limits<int>::max();
+
+ if (x >= static_cast<float>(s_intMax))
+ return s_intMax;
+ if (x < 0)
+ return 0;
+ return static_cast<int>(x);
}
inline int clampToInteger(unsigned value)
« no previous file with comments | « no previous file | Source/WebCore/platform/graphics/FloatRect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698