Index: src/xps/SkConstexprMath.h |
diff --git a/src/xps/SkConstexprMath.h b/src/xps/SkConstexprMath.h |
index 9625d5112b13b492952113fc9d25af8678037c14..0383ab3e67898505565f48c6088933788e926c4e 100644 |
--- a/src/xps/SkConstexprMath.h |
+++ b/src/xps/SkConstexprMath.h |
@@ -8,47 +8,24 @@ |
#ifndef SkConstexprMath_DEFINED |
#define SkConstexprMath_DEFINED |
-#include "SkTypes.h" |
-#include <limits.h> |
+#include <stdint.h> |
+#include <limits> |
-template <uintmax_t N, uintmax_t B> |
-struct SK_LOG { |
- //! Compile-time constant ceiling(logB(N)). |
- static const uintmax_t value = 1 + SK_LOG<N/B, B>::value; |
-}; |
-template <uintmax_t B> |
-struct SK_LOG<1, B> { |
- static const uintmax_t value = 0; |
-}; |
-template <uintmax_t B> |
-struct SK_LOG<0, B> { |
- static const uintmax_t value = 0; |
-}; |
+/** Compile-time constant floor(log_{b}(n)) */ |
bungeman-skia
2016/05/23 15:04:49
We don't want floor, we want ceiling. I think that
hal.canary
2016/05/23 16:55:39
function deleted.
|
+constexpr size_t SkLog(uintmax_t n, uintmax_t b) { |
+ return n <= 1 ? 0 : 1 + SkLog(n / b, b); |
+} |
-template<uintmax_t N> |
-struct SK_2N1 { |
- //! Compile-time constant (2^N)-1. |
- static const uintmax_t value = (SK_2N1<N-1>::value << 1) + 1; |
-}; |
-template<> |
-struct SK_2N1<1> { |
- static const uintmax_t value = 1; |
-}; |
- |
-/** Compile-time constant number of base n digits in type t |
- if the bits of type t are considered as unsigned base two. |
-*/ |
-#define SK_BASE_N_DIGITS_IN(n, t) (\ |
- SK_LOG<SK_2N1<(sizeof(t) * CHAR_BIT)>::value, n>::value\ |
-) |
/** Compile-time constant number of base 10 digits in type t |
bungeman-skia
2016/05/23 15:04:49
nit: 'type T'
(capitalized, since that's how its
hal.canary
2016/05/23 16:55:39
function deleted
|
- if the bits of type t are considered as unsigned base two. |
-*/ |
-#define SK_DIGITS_IN(t) SK_BASE_N_DIGITS_IN(10, (t)) |
+ if the bits of type t are considered as unsigned base two. */ |
+template <typename T> |
+constexpr size_t SkDigitsIn() { |
bungeman-skia
2016/05/23 15:04:49
Actually, now that I look, "std::numeric_limits::d
hal.canary
2016/05/23 16:55:39
Done.
|
+ return SkLog(std::numeric_limits<T>::max(), 10); |
+} |
-// Compile-time constant maximum value of two unsigned values. |
-template <uintmax_t a, uintmax_t b> struct SkTUMax { |
- static const uintmax_t value = (b < a) ? a : b; |
-}; |
+/** Compile-time constant maximum value of two size_t. */ |
+constexpr size_t SkSMax(size_t a, size_t b) { |
bungeman-skia
2016/05/23 15:04:49
If this is just used for size_t, just use SkTMax d
hal.canary
2016/05/23 16:55:39
Done.
|
+ return b < a ? a : b; |
+} |
#endif |