From 1b0d999c7a7cffc61192882cf2072d07207accc5 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Mon, 1 Apr 2024 21:27:41 +0200 Subject: [PATCH] Fix two places where CellAccessor::n_vertices is called repeatedly --- source/grid/grid_tools.cc | 9 +++++---- source/grid/tria_accessor.cc | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 879b88f052..c0adeb3d22 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -1081,11 +1081,12 @@ namespace GridTools const Point &position, const Mapping &mapping) { - const auto vertices = mapping.get_vertices(cell); - double minimum_distance = position.distance_square(vertices[0]); - unsigned int closest_vertex = 0; + const auto vertices = mapping.get_vertices(cell); + double minimum_distance = position.distance_square(vertices[0]); + unsigned int closest_vertex = 0; + const unsigned int n_vertices = cell->n_vertices(); - for (unsigned int v = 1; v < cell->n_vertices(); ++v) + for (unsigned int v = 1; v < n_vertices; ++v) { const double vertex_distance = position.distance_square(vertices[v]); if (vertex_distance < minimum_distance) diff --git a/source/grid/tria_accessor.cc b/source/grid/tria_accessor.cc index 000a1c2158..13f9c3bff0 100644 --- a/source/grid/tria_accessor.cc +++ b/source/grid/tria_accessor.cc @@ -1547,9 +1547,10 @@ TriaAccessor::bounding_box() const std::pair, Point> boundary_points = std::make_pair(this->vertex(0), this->vertex(0)); - for (unsigned int v = 1; v < this->n_vertices(); ++v) + const unsigned int n_vertices = this->n_vertices(); + for (unsigned int v = 1; v < n_vertices; ++v) { - const Point &x = this->vertex(v); + const Point x = this->vertex(v); for (unsigned int k = 0; k < spacedim; ++k) { boundary_points.first[k] = std::min(boundary_points.first[k], x[k]); -- 2.39.5