summaryrefslogtreecommitdiffstats
path: root/libcxx
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2011-07-24 21:45:06 +0000
committerHoward Hinnant <hhinnant@apple.com>2011-07-24 21:45:06 +0000
commit520a61383c467015635011d7e504850f7f9a1c8c (patch)
tree8586571c5a8673b8f9fcb6b75d517f00d1a9a62a /libcxx
parent640eddea29ae87fe745bfd915ab6d713d701117d (diff)
downloadbcm5719-llvm-520a61383c467015635011d7e504850f7f9a1c8c.tar.gz
bcm5719-llvm-520a61383c467015635011d7e504850f7f9a1c8c.zip
Optimization of string::operator< by M.E. O'Neill. Discussion in http://llvm.org/bugs/show_bug.cgi?id=10461
llvm-svn: 135893
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/include/string12
1 files changed, 11 insertions, 1 deletions
diff --git a/libcxx/include/string b/libcxx/include/string
index 91d6d30dc93..d1b9a5ea59a 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -3392,7 +3392,17 @@ _LIBCPP_INLINE_VISIBILITY inline
int
basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
{
- return compare(0, npos, __str.data(), __str.size());
+ size_t __lhs_sz = size();
+ size_t __rhs_sz = __str.size();
+ int __result = traits_type::compare(data(), __str.data(),
+ _VSTD::min(__lhs_sz, __rhs_sz));
+ if (__result != 0)
+ return __result;
+ if (__lhs_sz < __rhs_sz)
+ return -1;
+ if (__lhs_sz > __rhs_sz)
+ return 1;
+ return 0;
}
template <class _CharT, class _Traits, class _Allocator>
OpenPOWER on IntegriCloud