return true;
}
+
+ template<bool _BoolType>
+ struct __lexicographical_compare
+ {
+ template<typename _II1, typename _II2>
+ 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<true>
+ {
+ template<typename _Tp, typename _Up>
+ 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.
* then this is an inline call to @c memcmp.
*/
template<typename _II1, typename _II2>
- 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;
__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);
- // 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<char>::__is_signed)
- {
- typedef const signed char* value_type;
- value_type __f1 = reinterpret_cast<value_type>(__first1);
- value_type __l1 = reinterpret_cast<value_type>(__last1);
- value_type __f2 = reinterpret_cast<value_type>(__first2);
- value_type __l2 = reinterpret_cast<value_type>(__last2);
- return _GLIBCXX_STD_P::lexicographical_compare(__f1, __l1, __f2, __l2);
- }
- else
- {
- typedef const unsigned char* value_type;
- value_type __f1 = reinterpret_cast<value_type>(__first1);
- value_type __l1 = reinterpret_cast<value_type>(__last1);
- value_type __f2 = reinterpret_cast<value_type>(__first2);
- value_type __l2 = reinterpret_cast<value_type>(__last2);
- return _GLIBCXX_STD_P::lexicographical_compare(__f1, __l1, __f2, __l2);
- }
- }
+ return _GLIBCXX_STD_P::__lexicographical_compare<__simple>::
+ __lc(__first1, __last1, __first2, __last2);
+ }
/**
* @brief Performs "dictionary" comparison on ranges.