Cleanup: delegate to string_view equality for StringRef

This also fixes an issue introduced in rBd3e8d63a8c455d0,
where the function relied on the `StringRef` being null-terminated.
This commit is contained in:
Jacques Lucke 2023-01-11 13:19:11 +01:00
parent 8f7bb812c4
commit 5d07b0e6da
1 changed files with 2 additions and 18 deletions

View File

@ -604,28 +604,12 @@ inline std::string operator+(StringRef a, StringRef b)
* Ideally, we only use StringRef in our code to avoid this problem altogether. */
constexpr bool operator==(StringRef a, StringRef b)
{
if (a.size() != b.size()) {
return false;
}
if (a.data() == b.data()) {
/* This also avoids passing null to the call below when both are null,
* which would results in an ASAN warning. */
return true;
}
/* Account for a single value being null, resulting in an ASAN warning.
* Ensure an empty string is equal to a string with a null pointer. */
if (!a.data()) {
return *b.data() == '\0';
}
if (!b.data()) {
return *a.data() == '\0';
}
return STREQLEN(a.data(), b.data(), size_t(a.size()));
return std::string_view(a) == std::string_view(b);
}
constexpr bool operator!=(StringRef a, StringRef b)
{
return !(a == b);
return std::string_view(a) != std::string_view(b);
}
constexpr bool operator<(StringRef a, StringRef b)