From 9b0af34d9641156ee1c0ff7e1d1ff9386dd55d35 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 10 Jun 2014 18:51:55 +0000 Subject: [PATCH] Make the helper routines in string really be constexpr. This required a bit of refacoring in algorithm as well. Give them better names while we're at it. All of these are internal rotines; no visible functionality change. llvm-svn: 210561 --- libcxx/include/algorithm | 20 ++++++++--- libcxx/include/string | 88 +++++++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 48 deletions(-) diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm index 303ec7d..3b74a6b 100644 --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -975,7 +975,7 @@ __find_end(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1, } template -_RandomAccessIterator1 +_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __find_end(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag) @@ -1041,8 +1041,8 @@ find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, // find_first_of template -_ForwardIterator1 -find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, +_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1 +__find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { for (; __first1 != __last1; ++__first1) @@ -1052,6 +1052,16 @@ find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, return __last1; } + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator1 +find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred); +} + template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator1 @@ -1060,7 +1070,7 @@ find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, { typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; - return _VSTD::find_first_of(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); + return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); } // adjacent_find @@ -1440,7 +1450,7 @@ __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, } template -_RandomAccessIterator1 +_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag) diff --git a/libcxx/include/string b/libcxx/include/string index bb8f111..d07ff28 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -990,10 +990,10 @@ char_traits::assign(char_type* __s, size_t __n, char_type __a) // helper fns for basic_string -// __find +// __str_find template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__find(const _CharT *__p, _SizeT __sz, +__str_find(const _CharT *__p, _SizeT __sz, _CharT __c, _SizeT __pos) _NOEXCEPT { if (__pos >= __sz) @@ -1006,28 +1006,28 @@ __find(const _CharT *__p, _SizeT __sz, template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__find(const _CharT *__p, _SizeT __sz, +__str_find(const _CharT *__p, _SizeT __sz, const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT { if (__pos > __sz || __sz - __pos < __n) return __npos; if (__n == 0) return __pos; -// if (__n == 1) -// return _VSTD::__find<_CharT, _SizeT, _Traits, __npos>(__p, __sz, *__s, __pos); const _CharT* __r = - _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq); + _VSTD::__search(__p + __pos, __p + __sz, + __s, __s + __n, _Traits::eq, + random_access_iterator_tag(), random_access_iterator_tag()); if (__r == __p + __sz) return __npos; return static_cast<_SizeT>(__r - __p); } -// __rfind +// __str_rfind template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__rfind(const _CharT *__p, _SizeT __sz, +__str_rfind(const _CharT *__p, _SizeT __sz, _CharT __c, _SizeT __pos) _NOEXCEPT { if (__sz < 1) @@ -1046,7 +1046,7 @@ __rfind(const _CharT *__p, _SizeT __sz, template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__rfind(const _CharT *__p, _SizeT __sz, +__str_rfind(const _CharT *__p, _SizeT __sz, const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT { __pos = _VSTD::min(__pos, __sz); @@ -1054,21 +1054,23 @@ __rfind(const _CharT *__p, _SizeT __sz, __pos += __n; else __pos = __sz; - const _CharT* __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n, _Traits::eq); + const _CharT* __r = _VSTD::__find_end( + __p, __p + __pos, __s, __s + __n, _Traits::eq, + random_access_iterator_tag(), random_access_iterator_tag()); if (__n > 0 && __r == __p + __pos) return __npos; return static_cast<_SizeT>(__r - __p); } -// __find_first_of +// __str_find_first_of template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__find_first_of(const _CharT *__p, _SizeT __sz, +__str_find_first_of(const _CharT *__p, _SizeT __sz, const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT { if (__pos >= __sz || __n == 0) return __npos; - const _CharT* __r = _VSTD::find_first_of + const _CharT* __r = _VSTD::__find_first_of_ce (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq ); if (__r == __p + __sz) return __npos; @@ -1076,10 +1078,10 @@ __find_first_of(const _CharT *__p, _SizeT __sz, } -// __find_last_of +// __str_find_last_of template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__find_last_of(const _CharT *__p, _SizeT __sz, +__str_find_last_of(const _CharT *__p, _SizeT __sz, const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT { if (__n != 0) @@ -1099,10 +1101,10 @@ __find_last_of(const _CharT *__p, _SizeT __sz, } -// __find_first_not_of +// __str_find_first_not_of template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__find_first_not_of(const _CharT *__p, _SizeT __sz, +__str_find_first_not_of(const _CharT *__p, _SizeT __sz, const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT { if (__pos < __sz) @@ -1118,7 +1120,7 @@ __find_first_not_of(const _CharT *__p, _SizeT __sz, template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__find_first_not_of(const _CharT *__p, _SizeT __sz, +__str_find_first_not_of(const _CharT *__p, _SizeT __sz, _CharT __c, _SizeT __pos) _NOEXCEPT { if (__pos < __sz) @@ -1132,10 +1134,10 @@ __find_first_not_of(const _CharT *__p, _SizeT __sz, } -// __find_last_not_of +// __str_find_last_not_of template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__find_last_not_of(const _CharT *__p, _SizeT __sz, +__str_find_last_not_of(const _CharT *__p, _SizeT __sz, const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT { if (__pos < __sz) @@ -1151,7 +1153,7 @@ __find_last_not_of(const _CharT *__p, _SizeT __sz, template _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__find_last_not_of(const _CharT *__p, _SizeT __sz, +__str_find_last_not_of(const _CharT *__p, _SizeT __sz, _CharT __c, _SizeT __pos) _NOEXCEPT { if (__pos < __sz) @@ -3427,7 +3429,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); - return _VSTD::__find + return _VSTD::__str_find (data(), size(), __s, __pos, __n); } @@ -3437,7 +3439,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__find + return _VSTD::__str_find (data(), size(), __str.data(), __pos, __str.size()); } @@ -3448,7 +3450,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); - return _VSTD::__find + return _VSTD::__str_find (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3457,7 +3459,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, size_type __pos) const _NOEXCEPT { - return _VSTD::__find + return _VSTD::__str_find (data(), size(), __c, __pos); } @@ -3470,7 +3472,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); - return _VSTD::__rfind + return _VSTD::__str_rfind (data(), size(), __s, __pos, __n); } @@ -3480,7 +3482,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__rfind + return _VSTD::__str_rfind (data(), size(), __str.data(), __pos, __str.size()); } @@ -3491,7 +3493,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); - return _VSTD::__rfind + return _VSTD::__str_rfind (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3500,7 +3502,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, size_type __pos) const _NOEXCEPT { - return _VSTD::__rfind + return _VSTD::__str_rfind (data(), size(), __c, __pos); } @@ -3513,7 +3515,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); - return _VSTD::__find_first_of + return _VSTD::__str_find_first_of (data(), size(), __s, __pos, __n); } @@ -3523,7 +3525,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__find_first_of + return _VSTD::__str_find_first_of (data(), size(), __str.data(), __pos, __str.size()); } @@ -3534,7 +3536,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); - return _VSTD::__find_first_of + return _VSTD::__str_find_first_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3556,7 +3558,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); - return _VSTD::__find_last_of + return _VSTD::__str_find_last_of (data(), size(), __s, __pos, __n); } @@ -3566,7 +3568,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__find_last_of + return _VSTD::__str_find_last_of (data(), size(), __str.data(), __pos, __str.size()); } @@ -3577,7 +3579,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); - return _VSTD::__find_last_of + return _VSTD::__str_find_last_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3599,7 +3601,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _ size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); - return _VSTD::__find_first_not_of + return _VSTD::__str_find_first_not_of (data(), size(), __s, __pos, __n); } @@ -3609,7 +3611,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__find_first_not_of + return _VSTD::__str_find_first_not_of (data(), size(), __str.data(), __pos, __str.size()); } @@ -3620,7 +3622,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _ size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); - return _VSTD::__find_first_not_of + return _VSTD::__str_find_first_not_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3630,7 +3632,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, size_type __pos) const _NOEXCEPT { - return _VSTD::__find_first_not_of + return _VSTD::__str_find_first_not_of (data(), size(), __c, __pos); } @@ -3643,7 +3645,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __ size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); - return _VSTD::__find_last_not_of + return _VSTD::__str_find_last_not_of (data(), size(), __s, __pos, __n); } @@ -3653,7 +3655,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__find_last_not_of + return _VSTD::__str_find_last_not_of (data(), size(), __str.data(), __pos, __str.size()); } @@ -3664,7 +3666,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __ size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); - return _VSTD::__find_last_not_of + return _VSTD::__str_find_last_not_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3674,7 +3676,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, size_type __pos) const _NOEXCEPT { - return _VSTD::__find_last_not_of + return _VSTD::__str_find_last_not_of (data(), size(), __c, __pos); } -- 2.7.4