aboutsummaryrefslogtreecommitdiff
path: root/system/lib/libcxx/hash.cpp
diff options
context:
space:
mode:
authorBruce Mitchener <bruce.mitchener@gmail.com>2013-02-17 14:29:14 +0700
committerBruce Mitchener <bruce.mitchener@gmail.com>2013-03-25 00:34:11 +0700
commit59ff5a6a3c3e1f5255c5cf29f98df633a77b89b3 (patch)
treec7660fa62600366e3479dbf6b2fd1d25709af1b5 /system/lib/libcxx/hash.cpp
parent80fd6f0bce2b95db6ec539c9275ce24585550e7c (diff)
Update to current libcxx.
This doesn't work yet as it needs to be customized for use with emscripten still.
Diffstat (limited to 'system/lib/libcxx/hash.cpp')
-rw-r--r--system/lib/libcxx/hash.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/system/lib/libcxx/hash.cpp b/system/lib/libcxx/hash.cpp
index 728b9bd3..a0135002 100644
--- a/system/lib/libcxx/hash.cpp
+++ b/system/lib/libcxx/hash.cpp
@@ -10,6 +10,9 @@
#include "__hash_table"
#include "algorithm"
#include "stdexcept"
+#include "type_traits"
+
+#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -144,21 +147,23 @@ const unsigned indices[] =
// are fewer potential primes to search, and fewer potential primes to divide
// against.
+template <size_t _Sz = sizeof(size_t)>
inline _LIBCPP_INLINE_VISIBILITY
-void
-__check_for_overflow(size_t N, integral_constant<size_t, 32>)
+typename enable_if<_Sz == 4, void>::type
+__check_for_overflow(size_t N)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
+#ifndef _LIBCPP_NO_EXCEPTIONS
if (N > 0xFFFFFFFB)
throw overflow_error("__next_prime overflow");
#endif
}
+template <size_t _Sz = sizeof(size_t)>
inline _LIBCPP_INLINE_VISIBILITY
-void
-__check_for_overflow(size_t N, integral_constant<size_t, 64>)
+typename enable_if<_Sz == 8, void>::type
+__check_for_overflow(size_t N)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
+#ifndef _LIBCPP_NO_EXCEPTIONS
if (N > 0xFFFFFFFFFFFFFFC5ull)
throw overflow_error("__next_prime overflow");
#endif
@@ -174,14 +179,14 @@ __next_prime(size_t n)
return *std::lower_bound(small_primes, small_primes + N, n);
// Else n > largest small_primes
// Check for overflow
- __check_for_overflow(n, integral_constant<size_t,
- sizeof(n) * __CHAR_BIT__>());
+ __check_for_overflow(n);
// Start searching list of potential primes: L * k0 + indices[in]
const size_t M = sizeof(indices) / sizeof(indices[0]);
// Select first potential prime >= n
// Known a-priori n >= L
size_t k0 = n / L;
- size_t in = std::lower_bound(indices, indices + M, n - k0 * L) - indices;
+ size_t in = static_cast<size_t>(std::lower_bound(indices, indices + M, n - k0 * L)
+ - indices);
n = L * k0 + indices[in];
while (true)
{