mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
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.
This commit is contained in:
parent
2befd98da2
commit
e1dbad4c9e
@ -17,10 +17,6 @@ namespace Catch {
|
|||||||
: StringRef( rawChars, std::strlen(rawChars) )
|
: 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 {
|
bool StringRef::operator<(StringRef rhs) const noexcept {
|
||||||
if (m_size < rhs.m_size) {
|
if (m_size < rhs.m_size) {
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
/// A non-owning string class (similar to the forthcoming std::string_view)
|
/// A non-owning string class (similar to the forthcoming std::string_view)
|
||||||
@ -49,7 +51,10 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public: // operators
|
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 {
|
auto operator != (StringRef other) const noexcept -> bool {
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user