]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Resize a vector instead of repeatedly calling push_back. 4172/head
authorDavid Wells <wellsd2@rpi.edu>
Sat, 1 Apr 2017 16:53:46 +0000 (12:53 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 1 Apr 2017 18:32:35 +0000 (14:32 -0400)
std::vector<double>(0) creates an empty vector, so we can save some time by just
resizing the vector of vectors instead.

source/numerics/point_value_history.cc

index fbd5d18d1e1f84065491376310850e11068b435d..fe1ac2fb8a382328e2296831e0af6b81b87532da 100644 (file)
@@ -309,10 +309,7 @@ void PointValueHistory<dim>
       // entry
       const ComponentMask &current_mask = (component_mask.find (data_store_begin->first))->second;
       unsigned int n_stored = current_mask.n_selected_components();
-      for (unsigned int component = 0; component < n_stored; component++)
-        {
-          data_store_begin->second.push_back (std::vector<double> (0));
-        }
+      data_store_begin->second.resize(data_store_begin->second.size() + n_stored);
     }
 }
 
@@ -429,10 +426,7 @@ void PointValueHistory<dim>
           // entry
           const ComponentMask current_mask = (component_mask.find (data_store_begin->first))->second;
           unsigned int n_stored = current_mask.n_selected_components();
-          for (unsigned int component = 0; component < n_stored; component++)
-            {
-              data_store_begin->second.push_back (std::vector<double> (0));
-            }
+          data_store_begin->second.resize(data_store_begin->second.size() + n_stored);
         }
     }
 }

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.