summaryrefslogtreecommitdiff
path: root/hex.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-03-01 02:19:12 -0500
committerJeffrey Walton <noloader@gmail.com>2017-03-01 02:19:12 -0500
commit0dc97f1d3a801c33b16e746c1515f0723cf23790 (patch)
treef7414e418cabe48621759b6270ee75de60248fac /hex.cpp
parent62f92dd592a1685e7fee99165ec9350aee368c37 (diff)
downloadcryptopp-git-0dc97f1d3a801c33b16e746c1515f0723cf23790.tar.gz
Unroll decoder initialization (Issue 376)
Diffstat (limited to 'hex.cpp')
-rw-r--r--hex.cpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/hex.cpp b/hex.cpp
index 133c97e7..3871c4bd 100644
--- a/hex.cpp
+++ b/hex.cpp
@@ -29,16 +29,30 @@ void HexDecoder::IsolatedInitialize(const NameValuePairs &parameters)
MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 4, true)));
}
+ANONYMOUS_NAMESPACE_BEGIN
+static const int s_array[256] = {
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+};
+NAMESPACE_END
+
+// Unrolled initialization, http://github.com/weidai11/cryptopp/issues/376
const int *HexDecoder::GetDefaultDecodingLookupArray()
{
- static volatile bool s_initialized = false;
- static int s_array[256];
-
- if (!s_initialized)
- {
- InitializeDecodingLookupArray(s_array, s_vecUpper, 16, true);
- s_initialized = true;
- }
return s_array;
}