Explorar el Código

hashed_string: refine ctos and avoid uninitialized ::length in all cases

Michele Caini hace 2 años
padre
commit
ad743ff327
Se han modificado 2 ficheros con 4 adiciones y 4 borrados
  1. 2 2
      src/entt/core/hashed_string.hpp
  2. 2 2
      test/entt/core/hashed_string.cpp

+ 2 - 2
src/entt/core/hashed_string.hpp

@@ -131,7 +131,7 @@ public:
 
     /*! @brief Constructs an empty hashed string. */
     constexpr basic_hashed_string() noexcept
-        : base_type{} {}
+        : basic_hashed_string{nullptr, 0u} {}
 
     /**
      * @brief Constructs a hashed string from a string view.
@@ -167,7 +167,7 @@ public:
      * @return The size of the hashed string.
      */
     [[nodiscard]] constexpr size_type size() const noexcept {
-        return base_type::length; // NOLINT
+        return base_type::length;
     }
 
     /**

+ 2 - 2
test/entt/core/hashed_string.cpp

@@ -69,7 +69,7 @@ TEST(HashedString, Empty) {
     const entt::hashed_string hs{};
 
     ASSERT_EQ(hs.size(), 0u);
-    ASSERT_EQ(static_cast<hash_type>(hs), hash_type{});
+    ASSERT_EQ(static_cast<hash_type>(hs), entt::internal::fnv1a_traits<entt::id_type>::offset);
     ASSERT_EQ(static_cast<const char *>(hs), nullptr);
 }
 
@@ -163,7 +163,7 @@ TEST(HashedWString, Empty) {
     const entt::hashed_wstring hws{};
 
     ASSERT_EQ(hws.size(), 0u);
-    ASSERT_EQ(static_cast<hash_type>(hws), hash_type{});
+    ASSERT_EQ(static_cast<hash_type>(hws), entt::internal::fnv1a_traits<entt::id_type>::offset);
     ASSERT_EQ(static_cast<const wchar_t *>(hws), nullptr);
 }