https://bugs.webkit.org/show_bug.cgi?id=170662
Reviewed by Daniel Bates.
Source/WebCore:
* page/Frame.cpp:
Source/WTF:
Annotate Seconds' member functions and operators with constexpr.
It allows us to use Seconds calculation in compile time and use these
calculation for static const global variables.
operator% is an exception: it uses fmod and it is not offered as constexpr.
* wtf/MathExtras.h:
(defaultMinimumForClamp):
(defaultMaximumForClamp):
(clampToAccepting64):
Super unfortunate ugly code. This is because GCC 4.9 does not support C++14 relaxed constexpr.
* wtf/Seconds.h:
(WTF::Seconds::Seconds):
(WTF::Seconds::value):
(WTF::Seconds::minutes):
(WTF::Seconds::seconds):
(WTF::Seconds::milliseconds):
(WTF::Seconds::microseconds):
(WTF::Seconds::nanoseconds):
(WTF::Seconds::operator bool):
(WTF::Seconds::operator+):
(WTF::Seconds::operator-):
(WTF::Seconds::operator*):
(WTF::Seconds::operator/):
(WTF::Seconds::operator==):
(WTF::Seconds::operator!=):
(WTF::Seconds::operator<):
(WTF::Seconds::operator>):
(WTF::Seconds::operator<=):
(WTF::Seconds::operator>=):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215169
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2017-04-09 Yusuke Suzuki <utatane.tea@gmail.com>
+
+ [WTF] Annotate Seconds' member functions and operators with constexpr
+ https://bugs.webkit.org/show_bug.cgi?id=170662
+
+ Reviewed by Daniel Bates.
+
+ Annotate Seconds' member functions and operators with constexpr.
+ It allows us to use Seconds calculation in compile time and use these
+ calculation for static const global variables.
+
+ operator% is an exception: it uses fmod and it is not offered as constexpr.
+
+ * wtf/MathExtras.h:
+ (defaultMinimumForClamp):
+ (defaultMaximumForClamp):
+ (clampToAccepting64):
+ Super unfortunate ugly code. This is because GCC 4.9 does not support C++14 relaxed constexpr.
+
+ * wtf/Seconds.h:
+ (WTF::Seconds::Seconds):
+ (WTF::Seconds::value):
+ (WTF::Seconds::minutes):
+ (WTF::Seconds::seconds):
+ (WTF::Seconds::milliseconds):
+ (WTF::Seconds::microseconds):
+ (WTF::Seconds::nanoseconds):
+ (WTF::Seconds::operator bool):
+ (WTF::Seconds::operator+):
+ (WTF::Seconds::operator-):
+ (WTF::Seconds::operator*):
+ (WTF::Seconds::operator/):
+ (WTF::Seconds::operator==):
+ (WTF::Seconds::operator!=):
+ (WTF::Seconds::operator<):
+ (WTF::Seconds::operator>):
+ (WTF::Seconds::operator<=):
+ (WTF::Seconds::operator>=):
+
2017-04-09 Chris Dumez <cdumez@apple.com>
Start dropping Timer API dealing with double
inline float grad2rad(float g) { return g * piFloat / 200.0f; }
// std::numeric_limits<T>::min() returns the smallest positive value for floating point types
-template<typename T> inline T defaultMinimumForClamp() { return std::numeric_limits<T>::min(); }
-template<> inline float defaultMinimumForClamp() { return -std::numeric_limits<float>::max(); }
-template<> inline double defaultMinimumForClamp() { return -std::numeric_limits<double>::max(); }
-template<typename T> inline T defaultMaximumForClamp() { return std::numeric_limits<T>::max(); }
+template<typename T> constexpr inline T defaultMinimumForClamp() { return std::numeric_limits<T>::min(); }
+template<> constexpr inline float defaultMinimumForClamp() { return -std::numeric_limits<float>::max(); }
+template<> constexpr inline double defaultMinimumForClamp() { return -std::numeric_limits<double>::max(); }
+template<typename T> constexpr inline T defaultMaximumForClamp() { return std::numeric_limits<T>::max(); }
template<typename T> inline T clampTo(double value, T min = defaultMinimumForClamp<T>(), T max = defaultMaximumForClamp<T>())
{
// Explicitly accept 64bit result when clamping double value.
// Keep in mind that double can only represent 53bit integer precisely.
-template<typename T> inline T clampToAccepting64(double value, T min = defaultMinimumForClamp<T>(), T max = defaultMaximumForClamp<T>())
+template<typename T> constexpr inline T clampToAccepting64(double value, T min = defaultMinimumForClamp<T>(), T max = defaultMaximumForClamp<T>())
{
- if (value >= static_cast<double>(max))
- return max;
- if (value <= static_cast<double>(min))
- return min;
- return static_cast<T>(value);
+ return (value >= static_cast<double>(max)) ? max : ((value <= static_cast<double>(min)) ? min : static_cast<T>(value));
}
inline bool isWithinIntRange(float x)
class Seconds {
public:
- Seconds() { }
+ constexpr Seconds() { }
explicit constexpr Seconds(double value)
: m_value(value)
{
}
- double value() const { return m_value; }
+ constexpr double value() const { return m_value; }
- double minutes() const { return m_value / 60; }
- double seconds() const { return m_value; }
- double milliseconds() const { return seconds() * 1000; }
- double microseconds() const { return milliseconds() * 1000; }
- double nanoseconds() const { return microseconds() * 1000; }
+ constexpr double minutes() const { return m_value / 60; }
+ constexpr double seconds() const { return m_value; }
+ constexpr double milliseconds() const { return seconds() * 1000; }
+ constexpr double microseconds() const { return milliseconds() * 1000; }
+ constexpr double nanoseconds() const { return microseconds() * 1000; }
// Keep in mind that Seconds is held in double. If the value is not in range of 53bit integer, the result may not be precise.
template<typename T> T minutesAs() const { static_assert(std::is_integral<T>::value, ""); return clampToAccepting64<T>(minutes()); }
return Seconds(std::numeric_limits<double>::infinity());
}
- explicit operator bool() const { return !!m_value; }
+ explicit constexpr operator bool() const { return !!m_value; }
- Seconds operator+(Seconds other) const
+ constexpr Seconds operator+(Seconds other) const
{
return Seconds(value() + other.value());
}
- Seconds operator-(Seconds other) const
+ constexpr Seconds operator-(Seconds other) const
{
return Seconds(value() - other.value());
}
- Seconds operator-() const
+ constexpr Seconds operator-() const
{
return Seconds(-value());
}
// It makes sense to consider scaling a duration, like, "I want to wait 5 times as long as
// last time!".
- Seconds operator*(double scalar) const
+ constexpr Seconds operator*(double scalar) const
{
return Seconds(value() * scalar);
}
- Seconds operator/(double scalar) const
+ constexpr Seconds operator/(double scalar) const
{
return Seconds(value() / scalar);
}
// It's reasonable to think about ratios between Seconds.
- double operator/(Seconds other) const
+ constexpr double operator/(Seconds other) const
{
return value() / other.value();
}
WTF_EXPORT_PRIVATE MonotonicTime operator-(MonotonicTime) const;
WTF_EXPORT_PRIVATE TimeWithDynamicClockType operator-(const TimeWithDynamicClockType&) const;
- bool operator==(Seconds other) const
+ constexpr bool operator==(Seconds other) const
{
return m_value == other.m_value;
}
- bool operator!=(Seconds other) const
+ constexpr bool operator!=(Seconds other) const
{
return m_value != other.m_value;
}
- bool operator<(Seconds other) const
+ constexpr bool operator<(Seconds other) const
{
return m_value < other.m_value;
}
- bool operator>(Seconds other) const
+ constexpr bool operator>(Seconds other) const
{
return m_value > other.m_value;
}
- bool operator<=(Seconds other) const
+ constexpr bool operator<=(Seconds other) const
{
return m_value <= other.m_value;
}
- bool operator>=(Seconds other) const
+ constexpr bool operator>=(Seconds other) const
{
return m_value >= other.m_value;
}
+2017-04-09 Yusuke Suzuki <utatane.tea@gmail.com>
+
+ [WTF] Annotate Seconds' member functions and operators with constexpr
+ https://bugs.webkit.org/show_bug.cgi?id=170662
+
+ Reviewed by Daniel Bates.
+
+ * page/Frame.cpp:
+
2017-04-09 Chris Dumez <cdumez@apple.com>
Drop Timer::startRepeating() overload taking a double
using namespace HTMLNames;
#if PLATFORM(IOS)
-static const Seconds scrollFrequency { 1000 / 60. };
+static const Seconds scrollFrequency { 1000_s / 60. };
#endif
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, frameCounter, ("Frame"));