Explorar el Código

dense_set: refine constrained_find (perf)

skypjack hace 3 meses
padre
commit
17fb301636
Se han modificado 1 ficheros con 8 adiciones y 8 borrados
  1. 8 8
      src/entt/container/dense_set.hpp

+ 8 - 8
src/entt/container/dense_set.hpp

@@ -234,10 +234,10 @@ class dense_set {
     }
 
     template<typename Other>
-    [[nodiscard]] auto constrained_find(const Other &value, std::size_t bucket) {
-        for(auto it = begin(bucket), last = end(bucket); it != last; ++it) {
-            if(packed.second()(*it, value)) {
-                return begin() + static_cast<difference_type>(it.index());
+    [[nodiscard]] auto constrained_find(const Other &value, const std::size_t bucket) {
+        for(auto offset = sparse.first()[bucket]; offset != placeholder_position; offset = packed.first()[offset].first) {
+            if(packed.second()(packed.first()[offset].second, value)) {
+                return begin() + offset;
             }
         }
 
@@ -245,10 +245,10 @@ class dense_set {
     }
 
     template<typename Other>
-    [[nodiscard]] auto constrained_find(const Other &value, std::size_t bucket) const {
-        for(auto it = cbegin(bucket), last = cend(bucket); it != last; ++it) {
-            if(packed.second()(*it, value)) {
-                return cbegin() + static_cast<difference_type>(it.index());
+    [[nodiscard]] auto constrained_find(const Other &value, const std::size_t bucket) const {
+        for(auto offset = sparse.first()[bucket]; offset != placeholder_position; offset = packed.first()[offset].first) {
+            if(packed.second()(packed.first()[offset].second, value)) {
+                return cbegin() + offset;
             }
         }