Browse Source

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 years ago
parent
commit
ea25be8990
1 changed files with 5 additions and 3 deletions
  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.
     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.