Просмотр исходного кода

meta: fast lookup on meta_reset

skypjack 5 дней назад
Родитель
Сommit
31904e9506
2 измененных файлов с 11 добавлено и 8 удалено
  1. 3 3
      TODO
  2. 8 5
      src/entt/meta/factory.hpp

+ 3 - 3
TODO

@@ -24,7 +24,6 @@ TODO:
 * use unique_ptr or any for meta_custom_node
 * use unique_ptr or any for meta_custom_node
 * paged vector as a standalone class
 * paged vector as a standalone class
 * resource: shared_from_this?
 * resource: shared_from_this?
-* finish the imgui viewer/editor!
 * archetype-like a-là EnTT support (see my own notes)
 * archetype-like a-là EnTT support (see my own notes)
 * organizer: view/storage only based model, no registry
 * organizer: view/storage only based model, no registry
 * redesign snapshot as a whole
 * redesign snapshot as a whole
@@ -32,8 +31,9 @@ TODO:
 * storage: shrink_to_fit does not work with reentrant destructor?
 * storage: shrink_to_fit does not work with reentrant destructor?
 * make meta_any buffer size configurable (propagate to any)
 * make meta_any buffer size configurable (propagate to any)
 * test trivially_destructible optimization
 * test trivially_destructible optimization
+* try to fully support uint16_t for entity types
 * document stl and injections support (md)
 * document stl and injections support (md)
 * document new meta multi support (md)
 * document new meta multi support (md)
-* fast lookup on meta reset
 * use meta_any::type(value) with from_void and the like to avoid lookups in some cases
 * use meta_any::type(value) with from_void and the like to avoid lookups in some cases
-* try to fully support uint16_t for entity types
+* more tests for fast lookups on resolve and meta reset
+* finish the imgui viewer/editor!

+ 8 - 5
src/entt/meta/factory.hpp

@@ -571,11 +571,14 @@ public:
 inline void meta_reset(meta_ctx &ctx, const id_type alias) noexcept {
 inline void meta_reset(meta_ctx &ctx, const id_type alias) noexcept {
     auto &context = internal::meta_context::from(ctx);
     auto &context = internal::meta_context::from(ctx);
 
 
-    for(auto it = context.bucket.begin(); it != context.bucket.end();) {
-        if(it->second->alias == alias) {
-            it = context.bucket.erase(it);
-        } else {
-            ++it;
+    // fast path for unsearchable and overloaded types
+    if(context.bucket.erase(alias) == 0u) {
+        for(auto it = context.bucket.begin(); it != context.bucket.end();) {
+            if(it->second->alias == alias) {
+                it = context.bucket.erase(it);
+            } else {
+                ++it;
+            }
         }
         }
     }
     }
 }
 }