diff options
| author | Eric Fiselier <eric@efcs.ca> | 2015-08-28 03:02:37 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2015-08-28 03:02:37 +0000 |
| commit | 8465ea444001222e93b9bb0fc005407f7d72d1d5 (patch) | |
| tree | 8e15a66f0ca7e9febbebdbb3de3dbfec656cf68c /libcxx | |
| parent | ad5ca2245ef99413f521e6b0a4fc4ffc90e48da8 (diff) | |
| download | bcm5719-llvm-8465ea444001222e93b9bb0fc005407f7d72d1d5.tar.gz bcm5719-llvm-8465ea444001222e93b9bb0fc005407f7d72d1d5.zip | |
[libcxx] Optimize away unneeded length calculation in basic_string::compare(const char*)
Summary:
This patch optimizes basic_string::compare to use strcmp when the default char_traits has been given.
See PR19900 for more information. https://llvm.org/bugs/show_bug.cgi?id=19900
Reviewers: mclow.lists
Subscribers: bkramer, cfe-commits
Differential Revision: http://reviews.llvm.org/D12355
llvm-svn: 246266
Diffstat (limited to 'libcxx')
| -rw-r--r-- | libcxx/include/string | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libcxx/include/string b/libcxx/include/string index 372522cead7..504f9e1a0ac 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -3795,7 +3795,11 @@ bool operator==(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { - return __rhs.compare(__lhs) == 0; + typedef basic_string<_CharT, _Traits, _Allocator> _String; + _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); + size_t __lhs_len = _Traits::length(__lhs); + if (__lhs_len != __rhs.size()) return false; + return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; } template<class _CharT, class _Traits, class _Allocator> @@ -3804,7 +3808,11 @@ bool operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) == 0; + typedef basic_string<_CharT, _Traits, _Allocator> _String; + _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); + size_t __rhs_len = _Traits::length(__rhs); + if (__rhs_len != __lhs.size()) return false; + return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; } // operator!= |

