From 5932881291be0ef99abc72677fdf2507e9fd0fce Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 22 Jun 2019 15:59:54 +0200 Subject: [PATCH] Reduce reallocations and memory usage in gyroid --- src/libslic3r/Fill/FillGyroid.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libslic3r/Fill/FillGyroid.cpp b/src/libslic3r/Fill/FillGyroid.cpp index 7c6674556..ecc1d54a0 100644 --- a/src/libslic3r/Fill/FillGyroid.cpp +++ b/src/libslic3r/Fill/FillGyroid.cpp @@ -35,6 +35,7 @@ static inline Polyline make_wave( { std::vector points = one_period; double period = points.back()(0); + points.reserve(one_period.size() * floor(width / period)); points.pop_back(); int n = points.size(); do { @@ -44,6 +45,7 @@ static inline Polyline make_wave( // and construct the final polyline to return: Polyline polyline; + polyline.points.reserve(points.size()); for (auto& point : points) { point(1) += offset; point(1) = clamp(0., height, double(point(1))); @@ -60,6 +62,7 @@ static std::vector make_one_period(double width, double scaleFactor, doub std::vector points; double dx = M_PI_2; // exact coordinates on main inflexion lobes double limit = std::min(2*M_PI, width); + points.reserve(ceil(limit / tolerance / 3)); for (double x = 0.; x < limit + EPSILON; x += dx) { // so the last point is there too x = std::min(x, limit); points.emplace_back(Vec2d(x, f(x, z_sin, z_cos, vertical, flip)));