Skip to content

Commit

Permalink
Keyframe::FlipPoints() without temporary vector
Browse files Browse the repository at this point in the history
The Y coordinate of each point is adjusted inplace; reduces memory
overhead and iteration count for the loop.
  • Loading branch information
musteresel committed Nov 19, 2019
1 parent d539e46 commit 5ddc6a3
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/KeyFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

#include "../include/KeyFrame.h"
#include <utility>

using namespace std;
using namespace openshot;
Expand Down Expand Up @@ -904,17 +905,12 @@ void Keyframe::ScalePoints(double scale)
void Keyframe::FlipPoints()
{
// Loop through each point
std::vector<Point> FlippedPoints;
for (int64_t point_index = 0, reverse_index = Points.size() - 1; point_index < Points.size(); point_index++, reverse_index--) {
for (int64_t point_index = 0, reverse_index = Points.size() - 1; point_index < reverse_index; point_index++, reverse_index--) {
// Flip the points
Point p = Points[point_index];
p.co.Y = Points[reverse_index].co.Y;
FlippedPoints.push_back(p);
using std::swap;
swap(Points[point_index].co.Y, Points[reverse_index].co.Y);
}

// Swap vectors
Points.swap(FlippedPoints);

// Mark for re-processing
needs_update = true;
}

0 comments on commit 5ddc6a3

Please sign in to comment.