diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-11-18 13:46:21 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2014-12-13 05:10:20 +0100 |
commit | cfe12f716b0e138b51e3d8f5e481c4d9624459dc (patch) | |
tree | 26232a23b4985ba8984a139e03ac30403a38089d /src/corelib/tools/qbytearray.cpp | |
parent | 0bc6c4f7ecfa332de57500fe722872eff4009b9b (diff) |
Merge the different implementations of toHex in one central place
It's a simple enough function, but we don't need to duplicate those 17
bytes all over the place. Now they'll be duplicated at most once per
library.
Change-Id: Ic995e2a934b005e7e996e70f2ee644bfa948eb38
Reviewed-by: Jason McDonald <macadder1@gmail.com>
Diffstat (limited to 'src/corelib/tools/qbytearray.cpp')
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 26bf7d047d..bf29ebcd6d 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -4161,16 +4161,8 @@ QByteArray QByteArray::toHex() const char *hexData = hex.data(); const uchar *data = (const uchar *)d->data(); for (int i = 0; i < d->size; ++i) { - int j = (data[i] >> 4) & 0xf; - if (j <= 9) - hexData[i*2] = (j + '0'); - else - hexData[i*2] = (j + 'a' - 10); - j = data[i] & 0xf; - if (j <= 9) - hexData[i*2+1] = (j + '0'); - else - hexData[i*2+1] = (j + 'a' - 10); + hexData[i*2] = QtMiscUtils::toHexLower(data[i] >> 4); + hexData[i*2+1] = QtMiscUtils::toHexLower(data[i] & 0xf); } return hex; } @@ -4365,12 +4357,6 @@ static inline bool q_strchr(const char str[], char chr) return false; } -static inline char toHexHelper(char c) -{ - static const char hexnumbers[] = "0123456789ABCDEF"; - return hexnumbers[c & 0xf]; -} - static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const char *alsoEncode, char percent) { if (ba->isEmpty()) @@ -4403,8 +4389,8 @@ static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const ch output = ba->data(); } output[length++] = percent; - output[length++] = toHexHelper((c & 0xf0) >> 4); - output[length++] = toHexHelper(c & 0xf); + output[length++] = QtMiscUtils::toHexUpper((c & 0xf0) >> 4); + output[length++] = QtMiscUtils::toHexUpper(c & 0xf); } } if (output) |