From e21bd886eb4e9d42823202c06d9ebbf941c845ff Mon Sep 17 00:00:00 2001 From: Harry-Loud Date: Fri, 22 May 2026 11:01:57 +0100 Subject: [PATCH] Let vector growth handle exclusion preview fragments Remove the manual geometric reserve helper from clipped exclusion preview mesh accumulation. The append path now avoids exact per-fragment reserve calls and relies on std::vector amortized growth through emplace_back, matching standard container guidance. --- src/libslic3r/Model.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 74b55bb99e..83f4e4464f 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -3563,20 +3563,12 @@ static void append_clipped_polygon(indexed_triangle_set &out, const std::vector< if (polygon.size() < 3) return; - // Preview meshes may contain many clipped fragments, so grow geometrically - // instead of reserving the exact next size for every appended polygon. - auto reserve_geometric = [](auto &container, size_t wanted) { - if (wanted <= container.capacity()) - return; - container.reserve(std::max(wanted, std::max(16, container.capacity() * 2))); - }; - + // Do not reserve exact capacity here. This helper may be called for many + // clipped fragments, so let std::vector grow amortized through emplace_back. const int base = int(out.vertices.size()); - reserve_geometric(out.vertices, out.vertices.size() + polygon.size()); for (const Vec3d &point : polygon) out.vertices.emplace_back(point.cast()); - reserve_geometric(out.indices, out.indices.size() + polygon.size() - 2); for (size_t i = 1; i + 1 < polygon.size(); ++i) { stl_triangle_vertex_indices tri; tri << base, base + int(i), base + int(i + 1);