From c33e291474cdeae2ac9678ecf30d443d139169e3 Mon Sep 17 00:00:00 2001 From: Jakub Marcowski <01158831@pw.edu.pl> Date: Mon, 16 Oct 2023 12:26:59 +0200 Subject: [PATCH] Update `triangulate_delaunay()` to avoid needless reallocations --- core/math/geometry_2d.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index 0e5702e0af8..b37fce9e9c2 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -306,10 +306,12 @@ public: Vector tr = Delaunay2D::triangulate(p_points); Vector triangles; + triangles.resize(3 * tr.size()); + int *ptr = triangles.ptrw(); for (int i = 0; i < tr.size(); i++) { - triangles.push_back(tr[i].points[0]); - triangles.push_back(tr[i].points[1]); - triangles.push_back(tr[i].points[2]); + *ptr++ = tr[i].points[0]; + *ptr++ = tr[i].points[1]; + *ptr++ = tr[i].points[2]; } return triangles; }