Kaynağa Gözat

meta: refine the check when setting aliases to avoid conflicts with keys and support enabling fast lookups

skypjack 6 gün önce
ebeveyn
işleme
197c38ed34
2 değiştirilmiş dosya ile 4 ekleme ve 1 silme
  1. 1 1
      src/entt/meta/factory.hpp
  2. 3 0
      test/entt/meta/meta_factory.cpp

+ 1 - 1
src/entt/meta/factory.hpp

@@ -52,7 +52,7 @@ class basic_meta_factory {
     }
 
     bool unique_alias(const id_type alias) const noexcept {
-        return (stl::find_if(ctx->bucket.cbegin(), ctx->bucket.cend(), [alias](const auto &value) { return value.second->alias == alias; }) == ctx->bucket.cend());
+        return (ctx->bucket.find(alias) == ctx->bucket.cend()) && (stl::find_if(ctx->bucket.cbegin(), ctx->bucket.cend(), [alias](const auto &value) { return value.second->alias == alias; }) == ctx->bucket.cend());
     }
 
 protected:

+ 3 - 0
test/entt/meta/meta_factory.cpp

@@ -152,11 +152,14 @@ ENTT_DEBUG_TEST_F(MetaFactoryDeathTest, Type) {
     using namespace entt::literals;
 
     entt::meta_factory<int> factory{};
+    entt::meta_factory<int> overloaded{"overloaded"_hs};
     entt::meta_factory<double> other{};
 
     factory.type("foo"_hs);
+    overloaded.type("bar"_hs);
 
     ASSERT_DEATH(other.type("foo"_hs), "");
+    ASSERT_DEATH(other.type("overloaded"_hs), "");
 }
 
 TEST_F(MetaFactory, Base) {