diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index fd908991f0e..bb88fd153d2 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2007-11-16 Paolo Carlini + + * include/bits/stl_algobase.h (struct __lexicographical_compare): Add. + (lexicographical_compare<>(_II1, _II1, _II2, _II2)): Use it. + (lexicographical_compare(const unsigned char*, const unsigned char*, + const unsigned char*, const unsigned char*), + lexicographical_compare(const char*, const char*, const char*, + const char*)): Remove. + * include/ext/numeric_traits.h (__numeric_traits_floating<>:: + __is_signed): Add. + 2007-11-16 Paolo Carlini * src/locale_facets.cc: Fix typo in Copyright. diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 0c3f1b21c23..09d01457e90 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -877,6 +877,48 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) return true; } + + template + struct __lexicographical_compare + { + template + static bool + __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2) + { + typedef typename iterator_traits<_II1>::iterator_category _Category1; + typedef typename iterator_traits<_II2>::iterator_category _Category2; + typedef std::__lc_rai<_Category1, _Category2> __rai_type; + + __last1 = __rai_type::__newlast1(__first1, __last1, + __first2, __last2); + for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2); + ++__first1, ++__first2) + { + if (*__first1 < *__first2) + return true; + if (*__first2 < *__first1) + return false; + } + return __first1 == __last1 && __first2 != __last2; + } + }; + + template<> + struct __lexicographical_compare + { + template + static bool + __lc(const _Tp* __first1, const _Tp* __last1, + const _Up* __first2, const _Up* __last2) + { + const size_t __len1 = __last1 - __first1; + const size_t __len2 = __last2 - __first2; + const int __result = __builtin_memcmp(__first1, __first2, + std::min(__len1, __len2)); + return __result != 0 ? __result < 0 : __len1 < __len2; + } + }; + /** * @brief Performs "dictionary" comparison on ranges. * @param first1 An input iterator. @@ -892,14 +934,10 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) * then this is an inline call to @c memcmp. */ template - bool - lexicographical_compare(_II1 __first1, _II1 __last1, + inline bool + lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2) { - typedef typename iterator_traits<_II1>::iterator_category _Category1; - typedef typename iterator_traits<_II2>::iterator_category _Category2; - typedef std::__lc_rai<_Category1, _Category2> __rai_type; - // concept requirements typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; @@ -910,62 +948,17 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) __glibcxx_requires_valid_range(__first1, __last1); __glibcxx_requires_valid_range(__first2, __last2); - __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2); - for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2); - ++__first1, ++__first2) - { - if (*__first1 < *__first2) - return true; - if (*__first2 < *__first1) - return false; - } - return __first1 == __last1 && __first2 != __last2; + const bool __simple = + (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value + && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed + && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed + && __is_pointer<_II1>::__value + && __is_pointer<_II2>::__value); + + return _GLIBCXX_STD_P::__lexicographical_compare<__simple>:: + __lc(__first1, __last1, __first2, __last2); } - // XXX should these be enabled-if'd for signed/unsigned types instead? - inline bool - lexicographical_compare(const unsigned char* __first1, - const unsigned char* __last1, - const unsigned char* __first2, - const unsigned char* __last2) - { - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - const size_t __len1 = __last1 - __first1; - const size_t __len2 = __last2 - __first2; - const int __result = __builtin_memcmp(__first1, __first2, - std::min(__len1, __len2)); - return __result != 0 ? __result < 0 : __len1 < __len2; - } - - inline bool - lexicographical_compare(const char* __first1, const char* __last1, - const char* __first2, const char* __last2) - { - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - if (__gnu_cxx::__numeric_traits::__is_signed) - { - typedef const signed char* value_type; - value_type __f1 = reinterpret_cast(__first1); - value_type __l1 = reinterpret_cast(__last1); - value_type __f2 = reinterpret_cast(__first2); - value_type __l2 = reinterpret_cast(__last2); - return _GLIBCXX_STD_P::lexicographical_compare(__f1, __l1, __f2, __l2); - } - else - { - typedef const unsigned char* value_type; - value_type __f1 = reinterpret_cast(__first1); - value_type __l1 = reinterpret_cast(__last1); - value_type __f2 = reinterpret_cast(__first2); - value_type __l2 = reinterpret_cast(__last2); - return _GLIBCXX_STD_P::lexicographical_compare(__f1, __l1, __f2, __l2); - } - } - /** * @brief Performs "dictionary" comparison on ranges. * @param first1 An input iterator. diff --git a/libstdc++-v3/include/ext/numeric_traits.h b/libstdc++-v3/include/ext/numeric_traits.h index 109e37efc9e..29265e749f4 100644 --- a/libstdc++-v3/include/ext/numeric_traits.h +++ b/libstdc++-v3/include/ext/numeric_traits.h @@ -107,6 +107,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) static const int __max_digits10 = __glibcxx_max_digits10(_Value); // See above comment... + static const bool __is_signed = true; static const int __digits10 = __glibcxx_digits10(_Value); static const int __max_exponent10 = __glibcxx_max_exponent10(_Value); }; @@ -114,6 +115,9 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) template const int __numeric_traits_floating<_Value>::__max_digits10; + template + const bool __numeric_traits_floating<_Value>::__is_signed; + template const int __numeric_traits_floating<_Value>::__digits10;