From fa06d75e8df580bcb57418e67dbceb4168586d7f Mon Sep 17 00:00:00 2001 From: Howard Hinnant <hhinnant@apple.com> Date: Sun, 24 Jul 2011 21:45:06 +0000 Subject: [PATCH] Optimization of string::operator< by M.E. O'Neill. Discussion in http://llvm.org/bugs/show_bug.cgi?id=10461 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@135893 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/string | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/string b/include/string index 91d6d30d..d1b9a5ea 100644 --- a/include/string +++ b/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>