From: Martin Kronbichler Date: Mon, 1 Apr 2024 19:27:41 +0000 (+0200) Subject: Fix two places where CellAccessor::n_vertices is called repeatedly X-Git-Tag: v9.6.0-rc1~420^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b0d999c7a7cffc61192882cf2072d07207accc5;p=dealii.git Fix two places where CellAccessor::n_vertices is called repeatedly --- 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]);