diff options
author | Hal Canary <halcanary@google.com> | 2017-06-17 10:38:13 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-19 15:56:33 +0000 |
commit | d6e6e6699a85c6ed79e7d3b01e30d19e361ae049 (patch) | |
tree | 629683240e1596e0adfdc9d659f2687fe8a62cab /src/pdf/SkPDFMetadata.cpp | |
parent | 6d28730b2b13876601dec60caf49ba89e29c6fad (diff) |
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>
Diffstat (limited to 'src/pdf/SkPDFMetadata.cpp')
-rw-r--r-- | src/pdf/SkPDFMetadata.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/pdf/SkPDFMetadata.cpp b/src/pdf/SkPDFMetadata.cpp index ee5c19bba4..edef8515de 100644 --- a/src/pdf/SkPDFMetadata.cpp +++ b/src/pdf/SkPDFMetadata.cpp @@ -9,6 +9,8 @@ #include "SkMilestone.h" #include "SkPDFMetadata.h" #include "SkPDFTypes.h" +#include "SkUtils.h" + #include <utility> #define SKPDF_STRING(X) SKPDF_STRING_IMPL(X) @@ -120,35 +122,36 @@ sk_sp<SkPDFObject> SkPDFMetadata::MakePdfId(const UUID& doc, return array; } -#define HEXIFY(INPUT_PTR, OUTPUT_PTR, HEX_STRING, BYTE_COUNT) \ - do { \ - for (int i = 0; i < (BYTE_COUNT); ++i) { \ - uint8_t value = *(INPUT_PTR)++; \ - *(OUTPUT_PTR)++ = (HEX_STRING)[value >> 4]; \ - *(OUTPUT_PTR)++ = (HEX_STRING)[value & 0xF]; \ - } \ - } while (false) +// Convert a block of memory to hexadecimal. Input and output pointers will be +// moved to end of the range. +static void hexify(const uint8_t** inputPtr, char** outputPtr, int count) { + SkASSERT(inputPtr && *inputPtr); + SkASSERT(outputPtr && *outputPtr); + while (count-- > 0) { + uint8_t value = *(*inputPtr)++; + *(*outputPtr)++ = SkHexadecimalDigits::gLower[value >> 4]; + *(*outputPtr)++ = SkHexadecimalDigits::gLower[value & 0xF]; + } +} + static SkString uuid_to_string(const SkPDFMetadata::UUID& uuid) { // 8-4-4-4-12 char buffer[36]; // [32 + 4] - static const char gHex[] = "0123456789abcdef"; - SkASSERT(strlen(gHex) == 16); char* ptr = buffer; const uint8_t* data = uuid.fData; - HEXIFY(data, ptr, gHex, 4); + hexify(&data, &ptr, 4); *ptr++ = '-'; - HEXIFY(data, ptr, gHex, 2); + hexify(&data, &ptr, 2); *ptr++ = '-'; - HEXIFY(data, ptr, gHex, 2); + hexify(&data, &ptr, 2); *ptr++ = '-'; - HEXIFY(data, ptr, gHex, 2); + hexify(&data, &ptr, 2); *ptr++ = '-'; - HEXIFY(data, ptr, gHex, 6); + hexify(&data, &ptr, 6); SkASSERT(ptr == buffer + 36); SkASSERT(data == uuid.fData + 16); return SkString(buffer, 36); } -#undef HEXIFY namespace { class PDFXMLObject final : public SkPDFObject { |