Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2023-02-19 14:03:03 +0100
committerMartin Hořeňovský2023-02-20 15:05:09 +0100
commite1dbad4c9e9e5517c188cbd8af04cb6369851207 (patch)
tree94c416c873ad32a493f3c5c07c83e52b362500d2
parent2befd98da2b91c705de8fb0ea27bff662041f51c (diff)
downloadcatch3-e1dbad4c9e9e5517c188cbd8af04cb6369851207.tar.gz
Inline StringRef::operator==
This enables its inlining even without LTO, which in turns enables callers to determine that two StringRefs are unequals with simple comparison of two numbers, without any function calls.
-rw-r--r--src/catch2/internal/catch_stringref.cpp4
-rw-r--r--src/catch2/internal/catch_stringref.hpp7
2 files changed, 6 insertions, 5 deletions
diff --git a/src/catch2/internal/catch_stringref.cpp b/src/catch2/internal/catch_stringref.cpp
index 668ff297..232498eb 100644
--- a/src/catch2/internal/catch_stringref.cpp
+++ b/src/catch2/internal/catch_stringref.cpp
@@ -17,10 +17,6 @@ namespace Catch {
: StringRef( rawChars, std::strlen(rawChars) )
{}
- auto StringRef::operator == ( StringRef other ) const noexcept -> bool {
- return m_size == other.m_size
- && (std::memcmp( m_start, other.m_start, m_size ) == 0);
- }
bool StringRef::operator<(StringRef rhs) const noexcept {
if (m_size < rhs.m_size) {
diff --git a/src/catch2/internal/catch_stringref.hpp b/src/catch2/internal/catch_stringref.hpp
index bd8971bc..99bb9a98 100644
--- a/src/catch2/internal/catch_stringref.hpp
+++ b/src/catch2/internal/catch_stringref.hpp
@@ -13,6 +13,8 @@
#include <iosfwd>
#include <cassert>
+#include <cstring>
+
namespace Catch {
/// A non-owning string class (similar to the forthcoming std::string_view)
@@ -49,7 +51,10 @@ namespace Catch {
}
public: // operators
- auto operator == ( StringRef other ) const noexcept -> bool;
+ auto operator == ( StringRef other ) const noexcept -> bool {
+ return m_size == other.m_size
+ && (std::memcmp( m_start, other.m_start, m_size ) == 0);
+ }
auto operator != (StringRef other) const noexcept -> bool {
return !(*this == other);
}