Browse Source

meta: fast lookup for unsearchable and typeless types

skypjack 6 days ago
parent
commit
eda6234504
2 changed files with 10 additions and 4 deletions
  1. 0 1
      TODO
  2. 10 3
      src/entt/meta/resolve.hpp

+ 0 - 1
TODO

@@ -37,7 +37,6 @@ TODO:
 * use a dense_set for the meta context bucket to speed up lookups
 * new meta multi support: md and natvis
 * improve meta_reset and similar on multi contexts
-* improve resolve to support multi contexts (ie key == elem.id quick check)
 * use dense_set for meta context bucket to speed up lookups and reduce memory usage
 * review/refine/improve meta factory base for typed vs typeless types (ctor and type)
 * check coverage on new meta context features

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

@@ -58,9 +58,16 @@ template<typename Type>
  * @return The meta type associated with the given identifier, if any.
  */
 [[nodiscard]] inline meta_type resolve(const meta_ctx &ctx, const id_type id) noexcept {
-    for(auto &&curr: resolve(ctx)) {
-        if(curr.second.id() == id) {
-            return curr.second;
+    const auto &context = internal::meta_context::from(ctx);
+
+    // fast lookup for unsearchable and typeless types
+    if(const auto it = context.bucket.find(id); (it != context.bucket.end()) && (it->second->id == id)) {
+        return meta_type{ctx, *it->second};
+    }
+
+    for(auto &&curr: context.bucket) {
+        if(curr.second->id == id) {
+            return meta_type{ctx, *curr.second};
         }
     }