summaryrefslogtreecommitdiff
path: root/base32.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 /base32.cpp
parent62f92dd592a1685e7fee99165ec9350aee368c37 (diff)
downloadcryptopp-git-0dc97f1d3a801c33b16e746c1515f0723cf23790.tar.gz
Unroll decoder initialization (Issue 376)
Diffstat (limited to 'base32.cpp')
-rw-r--r--base32.cpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/base32.cpp b/base32.cpp
index 6444caba..f474de07 100644
--- a/base32.cpp
+++ b/base32.cpp
@@ -26,16 +26,30 @@ void Base32Decoder::IsolatedInitialize(const NameValuePairs &parameters)
MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 5, 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,
+ -1, -1, 24, 25, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, -1,
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -1, -1, -1, -1, -1,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, -1,
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -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 *Base32Decoder::GetDefaultDecodingLookupArray()
{
- static volatile bool s_initialized = false;
- static int s_array[256];
-
- if (!s_initialized)
- {
- InitializeDecodingLookupArray(s_array, s_vecUpper, 32, true);
- s_initialized = true;
- }
return s_array;
}