<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Apr 23, 2013, at 9:50 AM, Howard Hinnant <<a href="mailto:hhinnant@apple.com">hhinnant@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Apr 23, 2013, at 2:10 AM, Douglas Gregor <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:<br><br><blockquote type="cite"><br><br>Sent from my iPhone<br><br>On Apr 22, 2013, at 4:55 PM, Howard Hinnant <<a href="mailto:hhinnant@apple.com">hhinnant@apple.com</a>> wrote:<br><br><blockquote type="cite">Author: hhinnant<br>Date: Mon Apr 22 18:55:13 2013<br>New Revision: 180072<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=180072&view=rev">http://llvm.org/viewvc/llvm-project?rev=180072&view=rev</a><br>Log:<br>Modest performance improvement for std::string's operator==.<br><br>Modified:<br> libcxx/trunk/include/string<br><br>Modified: libcxx/trunk/include/string<br>URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=180072&r1=180071&r2=180072&view=diff">http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=180072&r1=180071&r2=180072&view=diff</a><br>==============================================================================<br>--- libcxx/trunk/include/string (original)<br>+++ libcxx/trunk/include/string Mon Apr 22 18:55:13 2013<br>@@ -1462,6 +1462,11 @@ public:<br> int compare(size_type __pos1, size_type __n1, const_pointer __s, size_type __n2) const;<br><br> _LIBCPP_INLINE_VISIBILITY bool __invariants() const;<br>+<br>+ _LIBCPP_INLINE_VISIBILITY<br>+ bool __is_long() const _NOEXCEPT<br>+ {return bool(__r_.first().__s.__size_ & __short_mask);}<br>+<br>private:<br> _LIBCPP_INLINE_VISIBILITY<br> allocator_type& __alloc() _NOEXCEPT<br>@@ -1471,10 +1476,6 @@ private:<br> {return __r_.second();}<br><br> _LIBCPP_INLINE_VISIBILITY<br>- bool __is_long() const _NOEXCEPT<br>- {return bool(__r_.first().__s.__size_ & __short_mask);}<br>-<br>- _LIBCPP_INLINE_VISIBILITY<br> void __set_short_size(size_type __s) _NOEXCEPT<br>#if _LIBCPP_BIG_ENDIAN<br> {__r_.first().__s.__size_ = (unsigned char)(__s);}<br>@@ -3561,9 +3562,29 @@ bool<br>operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,<br> const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT<br>{<br>- return __lhs.size() == __rhs.size() && _Traits::compare(__lhs.data(),<br>- __rhs.data(),<br>- __lhs.size()) == 0;<br>+ size_t __lhs_sz = __lhs.size();<br>+ return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),<br>+ __rhs.data(),<br>+ __lhs_sz) == 0;<br>+}<br>+<br>+template<class _Allocator><br>+_LIBCPP_INLINE_VISIBILITY inline<br>+bool<br>+operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,<br>+ const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT<br>+{<br>+ size_t __lhs_sz = __lhs.size();<br>+ if (__lhs_sz != __rhs.size())<br>+ return false;<br>+ const char* __lp = __lhs.data();<br>+ const char* __rp = __rhs.data();<br>+ if (__lhs.__is_long())<br>+ return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;<br>+ for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)<br>+ if (*__lp != *__rp)<br>+ return false;<br></blockquote><br>Shouldn't this go through traits for the character comparison?<br></blockquote><br><shrug> It could. There's no way to tell that it didn't. This is exactly what char_traits<char> would do, this function only uses char_traits<char>, and the client is not allowed to replace char_traits<char>. And if the client could detect that I wasn't calling char_traits<char>::eq, changing to call char_traits<char>::eq wouldn't make it conforming. The general form of this function is required to call Traits::compare, not Traits::eq.<br></div></blockquote></div><br><div>I missed the fact that this was a specialization for 'char'. Sorry for the noise.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>- Doug</div><div><br></div></body></html>