]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix two places where CellAccessor::n_vertices is called repeatedly 16831/head
authorMartin Kronbichler <martin.kronbichler@rub.de>
Mon, 1 Apr 2024 19:27:41 +0000 (21:27 +0200)
committerMartin Kronbichler <martin.kronbichler@rub.de>
Mon, 1 Apr 2024 19:27:41 +0000 (21:27 +0200)
source/grid/grid_tools.cc
source/grid/tria_accessor.cc

index 879b88f052fe22eab994cf78ab35fa9a397b8812..c0adeb3d22eacfe4b14d8e8fdcdd678ad1145d34 100644 (file)
@@ -1081,11 +1081,12 @@ namespace GridTools
     const Point<spacedim>                                             &position,
     const Mapping<dim, spacedim>                                      &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)
index 000a1c21587df7ccea591268496debff20c5debc..13f9c3bff0bedc840708fd97d6044bfc2bdc6ce1 100644 (file)
@@ -1547,9 +1547,10 @@ TriaAccessor<structdim, dim, spacedim>::bounding_box() const
   std::pair<Point<spacedim>, Point<spacedim>> 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<spacedim> &x = this->vertex(v);
+      const Point<spacedim> x = this->vertex(v);
       for (unsigned int k = 0; k < spacedim; ++k)
         {
           boundary_points.first[k]  = std::min(boundary_points.first[k], x[k]);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.