diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-05-30 11:44:02 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-05-30 11:44:02 +0000 |
commit | f9b9ebc24b11c314a7a3f0bd8fe531b13927507b (patch) | |
tree | 6f6e8369e567de7fd8c5c20ad4411ab2710e9574 /libstdc++-v3 | |
parent | d342df1826807be1e1ac5b6569ceda019163508a (diff) | |
download | gcc-f9b9ebc24b11c314a7a3f0bd8fe531b13927507b.tar.gz |
* include/bits/stl_algobase.h (__equal<true>::equal): Check length
instead of checking for null pointers.
(__lexicographical_compare<true>::__lc): Only check shorter length.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223886 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_algobase.h | 19 |
2 files changed, 12 insertions, 13 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c7b3b2d5ff4..19a4c14eaca 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2015-05-30 Jonathan Wakely <jwakely@redhat.com> + + * include/bits/stl_algobase.h (__equal<true>::equal): Check length + instead of checking for null pointers. + (__lexicographical_compare<true>::__lc): Only check shorter length. + 2015-05-29 François Dumont fdumont@gcc.gnu.org> * include/debug/debug.h (_GLIBCXX_DEBUG_ASSERT, diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index db065e2accd..12eb7ec61f8 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -812,11 +812,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static bool equal(const _Tp* __first1, const _Tp* __last1, const _Tp* __first2) { - if (__first1 == 0 || __first2 == 0) - return __first1 == __last1; - - return !__builtin_memcmp(__first1, __first2, sizeof(_Tp) - * (__last1 - __first1)); + if (const size_t __len = (__last1 - __first1)) + return !__builtin_memcmp(__first1, __first2, sizeof(_Tp) * __len); + return true; } }; @@ -920,14 +918,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { const size_t __len1 = __last1 - __first1; const size_t __len2 = __last2 - __first2; - if (__len1 && __len2) - { - if (int __result = __builtin_memcmp(__first1, __first2, - std::min(__len1, __len2))) - { - return __result < 0; - } - } + if (const size_t __len = std::min(__len1, __len2)) + if (int __result = __builtin_memcmp(__first1, __first2, __len)) + return __result < 0; return __len1 < __len2; } }; |