From: Wolfgang Bangerth Date: Fri, 7 Apr 2023 19:39:29 +0000 (-0600) Subject: Return objects by value, rather than via a reference. X-Git-Tag: v9.5.0-rc1~296^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80b24437feadd1d737b5efff67327508ff222c81;p=dealii.git Return objects by value, rather than via a reference. We now have move operators that apply to return objects, along with mandatory return value optimization. There is no readon not to use this. This patch applies this to some internal functions. I will write a separate patch to make this the case for the public interfaces that call these functions. --- diff --git a/source/dofs/dof_tools.cc b/source/dofs/dof_tools.cc index 6a676b6bb4..93470a2bff 100644 --- a/source/dofs/dof_tools.cc +++ b/source/dofs/dof_tools.cc @@ -2143,13 +2143,14 @@ namespace DoFTools namespace { template - void + std::map> map_dofs_to_support_points( - const hp::MappingCollection & mapping, - const DoFHandler & dof_handler, - std::map> &support_points, - const ComponentMask & in_mask) + const hp::MappingCollection &mapping, + const DoFHandler & dof_handler, + const ComponentMask & in_mask) { + std::map> support_points; + const hp::FECollection &fe_collection = dof_handler.get_fe_collection(); hp::QCollection q_coll_dummy; @@ -2208,23 +2209,24 @@ namespace DoFTools support_points[local_dof_indices[i]] = points[i]; } } + + return support_points; } template - void - map_dofs_to_support_points( + std::vector> + map_dofs_to_support_points_vector( const hp::MappingCollection &mapping, const DoFHandler & dof_handler, - std::vector> & support_points, const ComponentMask & mask) { + std::vector> support_points(dof_handler.n_dofs()); + // get the data in the form of the map as above - std::map> x_support_points; - map_dofs_to_support_points(mapping, - dof_handler, - x_support_points, - mask); + const std::map> + x_support_points = + map_dofs_to_support_points(mapping, dof_handler, mask); // now convert from the map to the linear vector. make sure every // entry really appeared in the map @@ -2233,12 +2235,15 @@ namespace DoFTools Assert(x_support_points.find(i) != x_support_points.end(), ExcInternalError()); - support_points[i] = x_support_points[i]; + support_points[i] = x_support_points.find(i)->second; } + + return support_points; } } // namespace } // namespace internal + template void map_dofs_to_support_points(const Mapping & mapping, @@ -2258,10 +2263,10 @@ namespace DoFTools // gets a MappingCollection const hp::MappingCollection mapping_collection(mapping); - internal::map_dofs_to_support_points(mapping_collection, - dof_handler, - support_points, - mask); + support_points = + internal::map_dofs_to_support_points_vector(mapping_collection, + dof_handler, + mask); } @@ -2283,10 +2288,8 @@ namespace DoFTools // Let the internal function do all the work, just make sure that it // gets a MappingCollection - internal::map_dofs_to_support_points(mapping, - dof_handler, - support_points, - mask); + support_points = + internal::map_dofs_to_support_points_vector(mapping, dof_handler, mask); } @@ -2304,10 +2307,9 @@ namespace DoFTools // gets a MappingCollection const hp::MappingCollection mapping_collection(mapping); - internal::map_dofs_to_support_points(mapping_collection, - dof_handler, - support_points, - mask); + support_points = internal::map_dofs_to_support_points(mapping_collection, + dof_handler, + mask); } @@ -2323,10 +2325,8 @@ namespace DoFTools // Let the internal function do all the work, just make sure that it // gets a MappingCollection - internal::map_dofs_to_support_points(mapping, - dof_handler, - support_points, - mask); + support_points = + internal::map_dofs_to_support_points(mapping, dof_handler, mask); } template