Explorar o código

meta: reduce symbol size of meta assoc traits ::insert_or_erase function

Michele Caini %!s(int64=2) %!d(string=hai) anos
pai
achega
2ad1a44432
Modificáronse 2 ficheiros con 5 adicións e 5 borrados
  1. 2 2
      src/entt/meta/container.hpp
  2. 3 3
      src/entt/meta/meta.hpp

+ 2 - 2
src/entt/meta/container.hpp

@@ -119,8 +119,8 @@ struct basic_meta_associative_container_traits {
         return iterator{ctx, std::bool_constant<key_only>{}, as_end ? cont->end() : cont->begin()};
     }
 
-    [[nodiscard]] static size_type insert_or_erase(any &container, meta_any &key, meta_any &value) {
-        if(auto *const cont = any_cast<Type>(&container); cont && key.allow_cast<const typename Type::key_type &>()) {
+    [[nodiscard]] static size_type insert_or_erase(void *container, meta_any &key, meta_any &value) {
+        if(auto *const cont = static_cast<Type *>(container); key.allow_cast<const typename Type::key_type &>()) {
             if(value) {
                 if constexpr(key_only) {
                     return cont->insert(key.cast<const typename Type::key_type &>()).second;

+ 3 - 3
src/entt/meta/meta.hpp

@@ -144,7 +144,7 @@ private:
     size_type (*size_fn)(const void *) noexcept {};
     bool (*clear_fn)(void *){};
     iterator (*iter_fn)(const meta_ctx &, void *, const void *, const bool){};
-    size_type (*insert_or_erase_fn)(any &, meta_any &, meta_any &){};
+    size_type (*insert_or_erase_fn)(void *, meta_any &, meta_any &){};
     iterator (*find_fn)(const meta_ctx &, void *, const void *, meta_any &){};
     any storage{};
 };
@@ -1973,7 +1973,7 @@ inline bool meta_associative_container::clear() {
  */
 inline bool meta_associative_container::insert(meta_any key) {
     meta_any value{*ctx, std::in_place_type<void>};
-    return (insert_or_erase_fn(storage, key, value) != 0u);
+    return (storage.policy() != any_policy::cref) && (insert_or_erase_fn(storage.data(), key, value) != 0u);
 }
 
 /**
@@ -1983,7 +1983,7 @@ inline bool meta_associative_container::insert(meta_any key) {
  * @return A bool denoting whether the insertion took place.
  */
 inline bool meta_associative_container::insert(meta_any key, meta_any value) {
-    return (insert_or_erase_fn(storage, key, value) != 0u);
+    return (storage.policy() != any_policy::cref) && (insert_or_erase_fn(storage.data(), key, value) != 0u);
 }
 
 /**