[cfe-commits] [libcxx] r113731 - in /libcxx/trunk: include/iterator include/type_traits src/hash.cpp
Howard Hinnant
hhinnant at apple.com
Sun Sep 12 18:43:27 PDT 2010
Author: hhinnant
Date: Sun Sep 12 20:43:27 2010
New Revision: 113731
URL: http://llvm.org/viewvc/llvm-project?rev=113731&view=rev
Log:
Experimenting with a new forward fomulation (kudos Daniel Kruegler), updated insert iterators to work better with pproxies, and doubled the speed of __next_prime.
Modified:
libcxx/trunk/include/iterator
libcxx/trunk/include/type_traits
libcxx/trunk/src/hash.cpp
Modified: libcxx/trunk/include/iterator
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=113731&r1=113730&r2=113731&view=diff
==============================================================================
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Sun Sep 12 20:43:27 2010
@@ -151,7 +151,7 @@
typedef void pointer;
explicit back_insert_iterator(Container& x);
- back_insert_iterator& operator=(typename Container::const_reference value);
+ back_insert_iterator& operator=(const typename _Container::value_type& value);
back_insert_iterator& operator*();
back_insert_iterator& operator++();
back_insert_iterator operator++(int);
@@ -172,7 +172,7 @@
typedef void pointer;
explicit front_insert_iterator(Container& x);
- front_insert_iterator& operator=(typename Container::const_reference value);
+ front_insert_iterator& operator=(const typename _Container::value_type& value);
front_insert_iterator& operator*();
front_insert_iterator& operator++();
front_insert_iterator operator++(int);
@@ -194,7 +194,7 @@
typedef void pointer;
insert_iterator(Container& x, typename Container::iterator i);
- insert_iterator& operator=(typename Container::const_reference value);
+ insert_iterator& operator=(const typename _Container::value_type& value);
insert_iterator& operator*();
insert_iterator& operator++();
insert_iterator& operator++(int);
@@ -624,7 +624,7 @@
typedef _Container container_type;
_LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {}
- _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::const_reference __value)
+ _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value)
{container->push_back(__value); return *this;}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value)
@@ -657,7 +657,7 @@
typedef _Container container_type;
_LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {}
- _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::const_reference __value)
+ _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value)
{container->push_front(__value); return *this;}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value)
@@ -692,7 +692,7 @@
_LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
: container(&__x), iter(__i) {}
- _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::const_reference __value)
+ _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value)
{iter = container->insert(iter, __value); ++iter; return *this;}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value)
Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=113731&r1=113730&r2=113731&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Sun Sep 12 20:43:27 2010
@@ -1302,6 +1302,28 @@
return static_cast<typename remove_reference<_Tp>::type&&>(__t);
}
+#if 1
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp&&
+forward(typename std::remove_reference<_Tp>::type& __t)
+{
+ return static_cast<_Tp&&>(__t);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp&&
+forward(typename std::remove_reference<_Tp>::type&& __t)
+{
+ static_assert(!std::is_lvalue_reference<_Tp>::value,
+ "Can not forward an rvalue as an lvalue.");
+ return static_cast<_Tp&&>(__t);
+}
+
+#else
+
template <class _Tp,
class = typename enable_if<
!is_lvalue_reference<_Tp>::value
@@ -1346,6 +1368,8 @@
_Tp
forward(typename remove_reference<_Tp>::type&& __t) = delete;
+#endif
+
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Tp>
Modified: libcxx/trunk/src/hash.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/hash.cpp?rev=113731&r1=113730&r2=113731&view=diff
==============================================================================
--- libcxx/trunk/src/hash.cpp (original)
+++ libcxx/trunk/src/hash.cpp Sun Sep 12 20:43:27 2010
@@ -157,7 +157,7 @@
// 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 % L) - indices;
+ size_t in = std::lower_bound(indices, indices + M, n - k0 * L) - indices;
n = L * k0 + indices[in];
while (true)
{
@@ -170,302 +170,352 @@
// small prime.
for (size_t j = 5; j < N - 1; ++j)
{
- if (n % small_primes[j] == 0)
- goto next;
- if (n / small_primes[j] < small_primes[j])
+ const std::size_t p = small_primes[j];
+ const std::size_t q = n / p;
+ if (q < p)
return n;
+ if (n == q * p)
+ goto next;
}
// n wasn't divisible by small primes, try potential primes
{
size_t i = 211;
while (true)
{
- if (n % i == 0)
- break;
- if (n / i < i)
+ std::size_t q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 10;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 8;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 8;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 6;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 4;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 2;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
i += 10;
- if (n % i == 0)
- break;
- if (n / i < i)
+ q = n / i;
+ if (q < i)
return n;
+ if (n == q * i)
+ break;
// This will loop i to the next "plane" of potential primes
i += 2;
More information about the cfe-commits
mailing list