Selaa lähdekoodia

improve performance of interation over Arrays

Kolja Strohm 22 tuntia sitten
vanhempi
commit
f210a9199a
1 muutettua tiedostoa jossa 10 lisäystä ja 9 poistoa
  1. 10 9
      Array.h

+ 10 - 9
Array.h

@@ -88,11 +88,12 @@ namespace Framework
     {
     private:
         ArrayEintrag<TYP>* current;
-        std::function<ArrayEintrag<TYP>*(ArrayEintrag<TYP>* removed)> onRemove;
+        const std::function<ArrayEintrag<TYP>*(ArrayEintrag<TYP>* removed)>*
+            onRemove;
 
     public:
         ArrayIterator(ArrayEintrag<TYP>* start,
-            std::function<ArrayEintrag<TYP>*(ArrayEintrag<TYP>* removed)>
+            const std::function<ArrayEintrag<TYP>*(ArrayEintrag<TYP>* removed)>*
                 onRemove)
         {
             this->onRemove = onRemove;
@@ -205,7 +206,7 @@ namespace Framework
 
         void remove() override
         {
-            current = onRemove(current);
+            current = (*onRemove)(current);
         }
     };
 
@@ -422,12 +423,12 @@ namespace Framework
         //! Mit ++ kann durch die Liste iteriert werden
         ArrayIterator<TYP> begin() const
         {
-            return ArrayIterator<TYP>(entries, onRemove);
+            return ArrayIterator<TYP>(entries, &onRemove);
         }
 
         ArrayIterator<TYP> end() const
         {
-            return ArrayIterator<TYP>(0, onRemove);
+            return ArrayIterator<TYP>(0, &onRemove);
         }
 
         //! Gibt zurück, wie viele Elemente in der Liste sind
@@ -512,7 +513,7 @@ namespace Framework
         Stream<TYP> stream()
         {
             return Stream<TYP>(new IteratorSupplier<TYP>(
-                new ArrayIterator<TYP>(entries, onRemove)));
+                new ArrayIterator<TYP>(entries, &onRemove)));
         }
     };
 
@@ -727,12 +728,12 @@ namespace Framework
         //! Mit ++ kann durch die Liste iteriert werden
         ArrayIterator<TYP*> begin() const
         {
-            return ArrayIterator<TYP*>(entries, onRemove);
+            return ArrayIterator<TYP*>(entries, &onRemove);
         }
 
         ArrayIterator<TYP*> end() const
         {
-            return ArrayIterator<TYP*>(0, onRemove);
+            return ArrayIterator<TYP*>(0, &onRemove);
         }
 
         //! Gibt zurück, wie viele Elemente in der Liste sind
@@ -837,7 +838,7 @@ namespace Framework
         Stream<TYP*> stream()
         {
             return Stream<TYP*>(new IteratorSupplier<TYP*>(
-                new ArrayIterator<TYP*>(entries, onRemove)));
+                new ArrayIterator<TYP*>(entries, &onRemove)));
         }
     };
 } // namespace Framework