]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use emplace_back over an in-place destructor/new. 7594/head
authorDavid Wells <drwells@email.unc.edu>
Sat, 12 Jan 2019 01:24:28 +0000 (20:24 -0500)
committerDavid Wells <drwells@email.unc.edu>
Sat, 12 Jan 2019 01:27:48 +0000 (20:27 -0500)
source/fe/fe_values.cc

index 8f17342c522e9b45cbeb2215a2c0debc302c0a16..0f682e841df96f2d5cdac54ef7daffed6dfc9bcd 100644 (file)
@@ -2642,75 +2642,40 @@ namespace internal
     {
       const FiniteElement<dim, spacedim> &fe = fe_values.get_fe();
 
-      // create the views objects: Allocate a bunch of default-constructed ones
-      // then destroy them again and do in-place construction of those we
-      // actually want to use.
       const unsigned int n_scalars = fe.n_components();
-      scalars.resize(n_scalars);
+      scalars.reserve(n_scalars);
       for (unsigned int component = 0; component < n_scalars; ++component)
-        {
-          // Use an alias here to work around an issue with gcc-4.1:
-          using ScalarView = dealii::FEValuesViews::Scalar<dim, spacedim>;
-          scalars[component].ScalarView::~ScalarView();
-
-          new (&scalars[component])
-            dealii::FEValuesViews::Scalar<dim, spacedim>(fe_values, component);
-        }
+        scalars.emplace_back(fe_values, component);
 
       // compute number of vectors that we can fit into this finite element.
       // note that this is based on the dimensionality 'dim' of the manifold,
       // not 'spacedim' of the output vector
       const unsigned int n_vectors =
         (fe.n_components() >= spacedim ? fe.n_components() - spacedim + 1 : 0);
-      vectors.resize(n_vectors);
+      vectors.reserve(n_vectors);
       for (unsigned int component = 0; component < n_vectors; ++component)
-        {
-          // Use an alias here to work around an issue with gcc-4.1:
-          using VectorView = dealii::FEValuesViews::Vector<dim, spacedim>;
-          vectors[component].VectorView::~VectorView();
-
-          new (&vectors[component])
-            dealii::FEValuesViews::Vector<dim, spacedim>(fe_values, component);
-        }
+        vectors.emplace_back(fe_values, component);
 
       // compute number of symmetric tensors in the same way as above
       const unsigned int n_symmetric_second_order_tensors =
         (fe.n_components() >= (dim * dim + dim) / 2 ?
            fe.n_components() - (dim * dim + dim) / 2 + 1 :
            0);
-      symmetric_second_order_tensors.resize(n_symmetric_second_order_tensors);
+      symmetric_second_order_tensors.reserve(n_symmetric_second_order_tensors);
       for (unsigned int component = 0;
            component < n_symmetric_second_order_tensors;
            ++component)
-        {
-          // Use an alias here to work around an issue with gcc-4.1:
-          using SymmetricTensorView =
-            dealii::FEValuesViews::SymmetricTensor<2, dim, spacedim>;
-          symmetric_second_order_tensors[component]
-            .SymmetricTensorView::~SymmetricTensorView();
-
-          new (&symmetric_second_order_tensors[component])
-            dealii::FEValuesViews::SymmetricTensor<2, dim, spacedim>(fe_values,
-                                                                     component);
-        }
+        symmetric_second_order_tensors.emplace_back(fe_values, component);
 
 
       // compute number of symmetric tensors in the same way as above
       const unsigned int n_second_order_tensors =
         (fe.n_components() >= dim * dim ? fe.n_components() - dim * dim + 1 :
                                           0);
-      second_order_tensors.resize(n_second_order_tensors);
+      second_order_tensors.reserve(n_second_order_tensors);
       for (unsigned int component = 0; component < n_second_order_tensors;
            ++component)
-        {
-          // Use an alias here to work around an issue with gcc-4.1:
-          using TensorView = dealii::FEValuesViews::Tensor<2, dim, spacedim>;
-          second_order_tensors[component].TensorView::~TensorView();
-
-          new (&second_order_tensors[component])
-            dealii::FEValuesViews::Tensor<2, dim, spacedim>(fe_values,
-                                                            component);
-        }
+        second_order_tensors.emplace_back(fe_values, component);
     }
   } // namespace FEValuesViews
 } // namespace internal

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.