[libcxx-commits] [PATCH] D59999: Allow the compiler to optimize `string == "literal string"`.
Samuel Benzaquen via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon May 6 08:16:54 PDT 2019
sbenza updated this revision to Diff 198284.
sbenza added a comment.
Another option for the optimzation.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59999/new/
https://reviews.llvm.org/D59999
Files:
libcxx/include/string
Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -3882,6 +3882,18 @@
return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
}
+template<>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const char* __lhs,
+ const string& __rhs) _NOEXCEPT
+{
+ _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
+ size_t __lhs_len = strlen(__lhs);
+ if (__lhs_len != __rhs.size()) return false;
+ return memcmp(__rhs.data(), __lhs, __lhs_len) == 0;
+}
+
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
@@ -3895,6 +3907,17 @@
return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
}
+template <>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const string& __lhs,
+ const char* __rhs) _NOEXCEPT {
+ _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
+ const size_t __rhs_len = strlen(__rhs);
+ if (__rhs_len != __lhs.size()) return false;
+ return memcmp(__lhs.data(), __rhs, __rhs_len) == 0;
+}
+
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59999.198284.patch
Type: text/x-patch
Size: 1285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190506/60f803ca/attachment.bin>
More information about the libcxx-commits
mailing list