[Bf-blender-cvs] [5d07b0e6da7] master: Cleanup: delegate to string_view equality for StringRef

Jacques Lucke noreply at git.blender.org
Wed Jan 11 13:19:23 CET 2023


Commit: 5d07b0e6da70d380a2d42fdade8caf02737342ad
Author: Jacques Lucke
Date:   Wed Jan 11 13:19:11 2023 +0100
Branches: master
https://developer.blender.org/rB5d07b0e6da70d380a2d42fdade8caf02737342ad

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.

===================================================================

M	source/blender/blenlib/BLI_string_ref.hh

===================================================================

diff --git a/source/blender/blenlib/BLI_string_ref.hh b/source/blender/blenlib/BLI_string_ref.hh
index 4f6f2cbfa41..f7606ccc860 100644
--- a/source/blender/blenlib/BLI_string_ref.hh
+++ b/source/blender/blenlib/BLI_string_ref.hh
@@ -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)



More information about the Bf-blender-cvs mailing list