Selaa lähdekoodia

Update Vector.h PODVector::Push

Went with cleaner implementation storing the other vector's size before resize rather than checking whether the other vector is this.
SirNate0 6 vuotta sitten
vanhempi
sitoutus
ea25be8990
1 muutettua tiedostoa jossa 5 lisäystä ja 3 poistoa
  1. 5 3
      Source/Urho3D/Container/Vector.h

+ 5 - 3
Source/Urho3D/Container/Vector.h

@@ -850,9 +850,11 @@ public:
     /// Add another vector at the end.
     /// Add another vector at the end.
     void Push(const PODVector<T>& vector)
     void Push(const PODVector<T>& vector)
     {
     {
-        unsigned oldSize = size_;
-        Resize(size_ + vector.size_);
-        CopyElements(Buffer() + oldSize, vector.Buffer(), (this == &vector) ? oldSize : vector.size_);
+        // Obtain the size before resizing, in case the other vector is another reference to this vector
+        unsigned thisSize = size_;
+        unsigned vectorSize = vector.size_;
+        Resize(thisSize + vectorSize);
+        CopyElements(Buffer() + thisSize, vector.Buffer(), vectorSize);
     }
     }
 
 
     /// Remove the last element.
     /// Remove the last element.