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

Unified Diff: include/core/SkTypes.h

Issue 1814153003: Templatize SkToXXX. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Chromium actually uses 4.6.4. Created 4 years, 9 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 | « include/core/SkString.h ('k') | include/private/SkTFitsIn.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkTypes.h
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index 1051f08ceaa807840cc361eb212e47377fed1ab2..d7a791163be3617b4c414d3f30d4da0982b141d0 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -256,27 +256,20 @@ typedef unsigned U16CPU;
*/
typedef uint8_t SkBool8;
-#ifdef SK_DEBUG
- SK_API int8_t SkToS8(intmax_t);
- SK_API uint8_t SkToU8(uintmax_t);
- SK_API int16_t SkToS16(intmax_t);
- SK_API uint16_t SkToU16(uintmax_t);
- SK_API int32_t SkToS32(intmax_t);
- SK_API uint32_t SkToU32(uintmax_t);
- SK_API int SkToInt(intmax_t);
- SK_API unsigned SkToUInt(uintmax_t);
- SK_API size_t SkToSizeT(uintmax_t);
-#else
- #define SkToS8(x) ((int8_t)(x))
- #define SkToU8(x) ((uint8_t)(x))
- #define SkToS16(x) ((int16_t)(x))
- #define SkToU16(x) ((uint16_t)(x))
- #define SkToS32(x) ((int32_t)(x))
- #define SkToU32(x) ((uint32_t)(x))
- #define SkToInt(x) ((int)(x))
- #define SkToUInt(x) ((unsigned)(x))
- #define SkToSizeT(x) ((size_t)(x))
-#endif
+#include "../private/SkTFitsIn.h"
+template <typename D, typename S> D SkTo(S s) {
+ SkASSERT(SkTFitsIn<D>(s));
+ return static_cast<D>(s);
+}
+#define SkToS8(x) SkTo<int8_t>(x)
+#define SkToU8(x) SkTo<uint8_t>(x)
+#define SkToS16(x) SkTo<int16_t>(x)
+#define SkToU16(x) SkTo<uint16_t>(x)
+#define SkToS32(x) SkTo<int32_t>(x)
+#define SkToU32(x) SkTo<uint32_t>(x)
+#define SkToInt(x) SkTo<int>(x)
+#define SkToUInt(x) SkTo<unsigned>(x)
+#define SkToSizeT(x) SkTo<size_t>(x)
/** Returns 0 or 1 based on the condition
*/
« no previous file with comments | « include/core/SkString.h ('k') | include/private/SkTFitsIn.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698