From 7f062a8f5e399ddb91c08cd1c56b4593caef449f Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Tue, 8 Apr 2025 09:20:57 +0200 Subject: [PATCH] ENH: return plain List instead of shrinking the DynamicList Using 'return List<T>(std::move(dynList))' for transfer of content (with implicit shrinking) into a plain List, and leave copy elision to do the rest. The implicit transfer (move construct List from DynamicList) will normally invoke resize (new/delete and moving elements). With 'return dynList.shrink()', it will first invoke an internal resize (new/delete and moving elements), followed by a copy construct as a plain list. STYLE: avoid implicit cast to 'const List&' in constructors --- .../IndirectList/IndirectListI.H | 4 ++- .../polyTopoChange/combineFaces.C | 2 +- .../polyTopoChange/removeCells.C | 2 +- src/fileFormats/vtk/part/foamVtuSizing.C | 36 +++++++++---------- .../vtk/read/vtkUnstructuredReader.C | 3 +- .../utilities/vtkWrite/vtkWriteUpdate.C | 2 +- ...edPointDisplacementPointPatchVectorField.C | 2 +- .../tools/lumpedPointTools.C | 15 ++++---- .../meshRefinement/meshRefinementBaffles.C | 3 +- src/meshTools/regionSplit/localPointRegion.C | 3 +- .../surfaceFeatures/surfaceFeatures.C | 2 +- src/surfMesh/MeshedSurface/MeshedSurface.C | 4 +-- .../abaqus/ABAQUSsurfaceFormat.C | 2 +- .../surfaceFormats/ac3d/AC3DsurfaceFormat.C | 4 +-- .../surfaceFormats/fire/FLMAsurfaceFormat.C | 2 +- .../surfaceFormats/gts/GTSsurfaceFormat.C | 2 +- .../surfaceFormats/nas/NASsurfaceFormat.C | 2 +- .../surfaceFormats/obj/OBJsurfaceFormat.C | 2 +- .../surfaceFormats/smesh/SMESHsurfaceFormat.C | 2 +- .../starcd/STARCDsurfaceFormat.C | 2 +- .../surfaceFormats/stl/STLsurfaceFormat.C | 4 +-- .../surfaceFormats/tri/TRIsurfaceFormat.C | 2 +- .../surfaceFormats/vtk/VTKsurfaceFormat.C | 2 +- .../surfaceFormats/vtp/VTPsurfaceFormat.C | 2 +- .../surfaceFormats/x3d/X3DsurfaceFormat.C | 2 +- 25 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectListI.H b/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectListI.H index d179d1c0bca..cb2d5e4fac1 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectListI.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectListI.H @@ -35,7 +35,8 @@ inline Foam::IndirectList<T>::IndirectList const labelUList& addr ) : - IndirectListAddressing<labelList>(addr), + // Copy addressing + IndirectListAddressing<labelList>(labelList(addr)), UIndirectList<T> ( values, @@ -51,6 +52,7 @@ inline Foam::IndirectList<T>::IndirectList labelList&& addr ) : + // Move addressing IndirectListAddressing<labelList>(std::move(addr)), UIndirectList<T> ( diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C index 0233e32c5dc..bcbe10bf8e2 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C @@ -409,7 +409,7 @@ Foam::labelListList Foam::combineFaces::getMergeSets } } - return allFaceSets.shrink(); + return labelListList(std::move(allFaceSets)); } diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.C index 8be969216cc..ab924692a2c 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.C @@ -180,7 +180,7 @@ Foam::labelList Foam::removeCells::getExposedFaces } } - return exposedFaces.shrink(); + return labelList(std::move(exposedFaces)); } diff --git a/src/fileFormats/vtk/part/foamVtuSizing.C b/src/fileFormats/vtk/part/foamVtuSizing.C index 87a99cac4b8..b8c6377c483 100644 --- a/src/fileFormats/vtk/part/foamVtuSizing.C +++ b/src/fileFormats/vtk/part/foamVtuSizing.C @@ -780,14 +780,13 @@ Foam::labelList Foam::vtk::vtuSizing::copyVertLabelsLegacy const label globalPointOffset ) { - if (!globalPointOffset) + labelList output(vertLabels); + + if (globalPointOffset) { - return vertLabels; + renumberVertLabelsLegacy(output, globalPointOffset); } - labelList output(vertLabels); - renumberVertLabelsLegacy(output, globalPointOffset); - return output; } @@ -863,14 +862,13 @@ Foam::labelList Foam::vtk::vtuSizing::copyVertLabelsXml const label globalPointOffset ) { - if (!globalPointOffset) + labelList output(vertLabels); + + if (globalPointOffset) { - return vertLabels; + renumberVertLabelsXml(output, globalPointOffset); } - labelList output(vertLabels); - renumberVertLabelsXml(output, globalPointOffset); - return output; } @@ -902,14 +900,13 @@ Foam::labelList Foam::vtk::vtuSizing::copyFaceLabelsXml const label globalPointOffset ) { - if (!globalPointOffset) + labelList output(faceLabels); + + if (globalPointOffset) { - return faceLabels; + renumberFaceLabelsXml(output, globalPointOffset); } - labelList output(faceLabels); - renumberFaceLabelsXml(output, globalPointOffset); - return output; } @@ -957,14 +954,13 @@ Foam::labelList Foam::vtk::vtuSizing::copyFaceOffsetsXml const label prevOffset ) { - if (!prevOffset) + labelList output(faceOffsets); + + if (prevOffset) { - return faceOffsets; + renumberFaceOffsetsXml(output, prevOffset); } - labelList output(faceOffsets); - renumberFaceOffsetsXml(output, prevOffset); - return output; } diff --git a/src/fileFormats/vtk/read/vtkUnstructuredReader.C b/src/fileFormats/vtk/read/vtkUnstructuredReader.C index 40b45b37e77..71a64a8ae28 100644 --- a/src/fileFormats/vtk/read/vtkUnstructuredReader.C +++ b/src/fileFormats/vtk/read/vtkUnstructuredReader.C @@ -566,7 +566,8 @@ Foam::wordList Foam::vtkUnstructuredReader::readFieldArray ); fields.append(arrayName); } - return fields.shrink(); + + return wordList(std::move(fields)); } diff --git a/src/functionObjects/utilities/vtkWrite/vtkWriteUpdate.C b/src/functionObjects/utilities/vtkWrite/vtkWriteUpdate.C index 45ed8fdc3af..57c67cc1869 100644 --- a/src/functionObjects/utilities/vtkWrite/vtkWriteUpdate.C +++ b/src/functionObjects/utilities/vtkWrite/vtkWriteUpdate.C @@ -78,7 +78,7 @@ Foam::labelList Foam::functionObjects::vtkWrite::getSelectedPatches } } - return patchIDs.shrink(); + return labelList(std::move(patchIDs)); } diff --git a/src/lumpedPointMotion/pointPatchFields/lumpedPointDisplacementPointPatchVectorField.C b/src/lumpedPointMotion/pointPatchFields/lumpedPointDisplacementPointPatchVectorField.C index b10fe98d72d..160a9f75bad 100644 --- a/src/lumpedPointMotion/pointPatchFields/lumpedPointDisplacementPointPatchVectorField.C +++ b/src/lumpedPointMotion/pointPatchFields/lumpedPointDisplacementPointPatchVectorField.C @@ -137,7 +137,7 @@ Foam::lumpedPointDisplacementPointPatchVectorField::patchIds } } - return patchLst.shrink(); + return labelList(std::move(patchLst)); } diff --git a/src/lumpedPointMotion/tools/lumpedPointTools.C b/src/lumpedPointMotion/tools/lumpedPointTools.C index eba1d49d058..d676f6df2c9 100644 --- a/src/lumpedPointMotion/tools/lumpedPointTools.C +++ b/src/lumpedPointMotion/tools/lumpedPointTools.C @@ -92,21 +92,24 @@ Foam::lumpedPointTools::lumpedPointStates Info<<"Reading states\n"; List<dictionary> entries(dict.lookup("response")); - DynamicList<Tuple2<scalar, lumpedPointState>> states(entries.size()); + label statei = 0; + + // List<lumpedPointStateTuple> + List<Tuple2<scalar, lumpedPointState>> states(entries.size()); for (const dictionary& subDict : entries) { - states.append - ( + states[statei] = lumpedPointStateTuple ( subDict.get<scalar>("time"), lumpedPointState(subDict) - ) - ); + ); + + ++statei; } - return states.shrink(); + return states; } diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C index 2c92d2f0591..7a233dc9022 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C @@ -3995,7 +3995,8 @@ Foam::labelList Foam::meshRefinement::freeStandingBaffleFaces } } } - return faceLabels.shrink(); + + return labelList(std::move(faceLabels)); } diff --git a/src/meshTools/regionSplit/localPointRegion.C b/src/meshTools/regionSplit/localPointRegion.C index c4dd9b2eef8..df78dbd4d6c 100644 --- a/src/meshTools/regionSplit/localPointRegion.C +++ b/src/meshTools/regionSplit/localPointRegion.C @@ -677,7 +677,8 @@ Foam::List<Foam::labelPair> Foam::localPointRegion::findDuplicateFacePairs } } } - return baffles.shrink(); + + return List<labelPair>(std::move(baffles)); } diff --git a/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C b/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C index 9242d8c7d43..bd942e25d10 100644 --- a/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C +++ b/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C @@ -1113,7 +1113,7 @@ Foam::labelList Foam::surfaceFeatures::selectFeatureEdges } } - return selectedEdges.shrink(); + return labelList(std::move(selectedEdges)); } diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C index 3feb342a7b9..30516a5518c 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.C +++ b/src/surfMesh/MeshedSurface/MeshedSurface.C @@ -277,7 +277,7 @@ Foam::MeshedSurface<Face>::MeshedSurface const UList<surfZone>& zoneLst ) : - MeshReference(faceLst, pointLst), // Copy construct + MeshReference(List<Face>(faceLst), pointLst), // Copy construct faceIds_(), zones_(zoneLst) { @@ -310,7 +310,7 @@ Foam::MeshedSurface<Face>::MeshedSurface const UList<word>& zoneNames ) : - MeshReference(faceLst, pointLst), // Copy construct + MeshReference(List<Face>(faceLst), pointLst), // Copy construct faceIds_(), zones_() { diff --git a/src/surfMesh/surfaceFormats/abaqus/ABAQUSsurfaceFormat.C b/src/surfMesh/surfaceFormats/abaqus/ABAQUSsurfaceFormat.C index a58d42cbc28..843d1f21c65 100644 --- a/src/surfMesh/surfaceFormats/abaqus/ABAQUSsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/abaqus/ABAQUSsurfaceFormat.C @@ -253,7 +253,7 @@ void Foam::fileFormats::ABAQUSsurfaceFormat<Face>::write const UList<label>& elemIds = surf.faceIds(); // for no zones, suppress the group name - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst, "") diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C index 6e84873870c..9894bdfc31d 100644 --- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C @@ -314,7 +314,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write const pointField& pointLst = surf.points(); const UList<Face>& faceLst = surf.surfFaces(); - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().size() ? surf.surfZones() @@ -404,7 +404,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write if (zoneLst.size() <= 1) { - const surfZoneList zones = + const surfZoneList zones ( zoneLst.size() ? zoneLst diff --git a/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C b/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C index a1d6d2bd2d7..40673c202da 100644 --- a/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C @@ -174,7 +174,7 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write const UList<label>& faceMap = surf.faceMap(); // for no zones, suppress the group name - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst, word::null) diff --git a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C index 01bf468340d..7476da7fdf9 100644 --- a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C @@ -260,7 +260,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write const UList<point>& pointLst = surf.points(); const UList<Face>& faceLst = surf.surfFaces(); - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().size() ? surf.surfZones() diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C index 6b4e8e03103..273fa4e5884 100644 --- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C @@ -594,7 +594,7 @@ void Foam::fileFormats::NASsurfaceFormat<Face>::write const UList<label>& elemIds = surf.faceIds(); // for no zones, suppress the group name - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst, "") diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C index 1383a9d0702..65af4894368 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C @@ -239,7 +239,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write const UList<label>& faceMap = surf.faceMap(); // for no zones, suppress the group name - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst, "") diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C index 5f576f0cf2b..6ca8b27983d 100644 --- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C @@ -48,7 +48,7 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write const UList<Face>& faceLst = surf.surfFaces(); const UList<label>& faceMap = surf.faceMap(); - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst) diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C index 4b761f239bd..082f7a28953 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C @@ -270,7 +270,7 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write const UList<label>& faceMap = surf.faceMap(); const UList<label>& elemIds = surf.faceIds(); - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst) diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C index d68f2da2de2..94272f9dad1 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C @@ -219,7 +219,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii const UList<Face>& faceLst = surf.surfFaces(); const UList<label>& faceMap = surf.faceMap(); - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst) @@ -266,7 +266,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary const UList<Face>& faceLst = surf.surfFaces(); const UList<label>& faceMap = surf.faceMap(); - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().size() > 1 ? surf.surfZones() diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C index 736671ef7a4..63416d09f43 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C @@ -168,7 +168,7 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write const UList<Face>& faceLst = surf.surfFaces(); const UList<label>& faceMap = surf.faceMap(); - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst) diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C index 555233d6e0b..ebd2ef95aef 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C @@ -255,7 +255,7 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write const UList<Face>& faceLst = surf.surfFaces(); const UList<label>& faceMap = surf.faceMap(); - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst) diff --git a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C index 3d06b741e0f..1bec7447528 100644 --- a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C @@ -104,7 +104,7 @@ void Foam::fileFormats::VTPsurfaceFormat<Face>::write const UList<Face>& faceLst = surf.surfFaces(); const UList<label>& faceMap = surf.faceMap(); - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst) diff --git a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C index 584af35c678..e95d7a79263 100644 --- a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C @@ -48,7 +48,7 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write const UList<label>& faceMap = surf.faceMap(); // for no zones, suppress the group name - const surfZoneList zones = + const surfZoneList zones ( surf.surfZones().empty() ? surfaceFormatsCore::oneZone(faceLst, word::null) -- GitLab