Skip to content

Commit 5ddc6a3

Browse files
committed
Keyframe::FlipPoints() without temporary vector
The Y coordinate of each point is adjusted inplace; reduces memory overhead and iteration count for the loop.
1 parent d539e46 commit 5ddc6a3

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/KeyFrame.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030

3131
#include "../include/KeyFrame.h"
32+
#include <utility>
3233

3334
using namespace std;
3435
using namespace openshot;
@@ -904,17 +905,12 @@ void Keyframe::ScalePoints(double scale)
904905
void Keyframe::FlipPoints()
905906
{
906907
// Loop through each point
907-
std::vector<Point> FlippedPoints;
908-
for (int64_t point_index = 0, reverse_index = Points.size() - 1; point_index < Points.size(); point_index++, reverse_index--) {
908+
for (int64_t point_index = 0, reverse_index = Points.size() - 1; point_index < reverse_index; point_index++, reverse_index--) {
909909
// Flip the points
910-
Point p = Points[point_index];
911-
p.co.Y = Points[reverse_index].co.Y;
912-
FlippedPoints.push_back(p);
910+
using std::swap;
911+
swap(Points[point_index].co.Y, Points[reverse_index].co.Y);
913912
}
914913

915-
// Swap vectors
916-
Points.swap(FlippedPoints);
917-
918914
// Mark for re-processing
919915
needs_update = true;
920916
}

0 commit comments

Comments
 (0)