factor out hexadecimal constants.
Now we don't have to rely on the linker to de-duplicate
so many gHex[] constants.
Change-Id: Ia86d3a92648415afdb8d29499b4faded5ed05c7d
Reviewed-on: https://skia-review.googlesource.com/20180
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/src/core/SkICC.cpp b/src/core/SkICC.cpp
index c26f6d8..7eaf667 100644
--- a/src/core/SkICC.cpp
+++ b/src/core/SkICC.cpp
@@ -15,6 +15,7 @@
#include "SkICC.h"
#include "SkICCPriv.h"
#include "SkMD5.h"
+#include "SkUtils.h"
SkICC::SkICC(sk_sp<SkColorSpace> colorSpace)
: fColorSpace(std::move(colorSpace))
@@ -332,11 +333,10 @@
SkMD5::Digest digest;
md5.finish(digest);
for (unsigned i = 0; i < sizeof(SkMD5::Digest); ++i) {
- static const char gHex[] = "0123456789ABCDEF";
*ptr++ = 0;
- *ptr++ = gHex[digest.data[i] >> 4];
+ *ptr++ = SkHexadecimalDigits::gUpper[digest.data[i] >> 4];
*ptr++ = 0;
- *ptr++ = gHex[digest.data[i] & 0xF];
+ *ptr++ = SkHexadecimalDigits::gUpper[digest.data[i] & 0xF];
}
SkASSERT(ptr == ptrCheck + kDescriptionTagBodySize + sizeof(kDescriptionTagHeader));
}
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index 528c602..8eee127 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -539,13 +539,11 @@
void SkString::insertHex(size_t offset, uint32_t hex, int minDigits) {
minDigits = SkTPin(minDigits, 0, 8);
- static const char gHex[] = "0123456789ABCDEF";
-
char buffer[8];
char* p = buffer + sizeof(buffer);
do {
- *--p = gHex[hex & 0xF];
+ *--p = SkHexadecimalDigits::gUpper[hex & 0xF];
hex >>= 4;
minDigits -= 1;
} while (hex != 0);
diff --git a/src/core/SkUtils.cpp b/src/core/SkUtils.cpp
index 85ebb3e..1eb2a7d 100644
--- a/src/core/SkUtils.cpp
+++ b/src/core/SkUtils.cpp
@@ -355,3 +355,9 @@
}
return size;
}
+
+const char SkHexadecimalDigits::gUpper[16] =
+ { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+const char SkHexadecimalDigits::gLower[16] =
+ { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
diff --git a/src/core/SkUtils.h b/src/core/SkUtils.h
index 2ae6f87..832bdbd 100644
--- a/src/core/SkUtils.h
+++ b/src/core/SkUtils.h
@@ -107,4 +107,10 @@
}
return true;
}
+
+namespace SkHexadecimalDigits {
+ extern const char gUpper[16]; // 0-9A-F
+ extern const char gLower[16]; // 0-9a-f
+}
+
#endif