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
This commit is contained in:
Mark Olesen 2025-04-08 09:20:57 +02:00
parent f13a05375c
commit 7f062a8f5e
25 changed files with 60 additions and 56 deletions

View File

@ -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>
(

View File

@ -409,7 +409,7 @@ Foam::labelListList Foam::combineFaces::getMergeSets
}
}
return allFaceSets.shrink();
return labelListList(std::move(allFaceSets));
}

View File

@ -180,7 +180,7 @@ Foam::labelList Foam::removeCells::getExposedFaces
}
}
return exposedFaces.shrink();
return labelList(std::move(exposedFaces));
}

View File

@ -780,13 +780,12 @@ Foam::labelList Foam::vtk::vtuSizing::copyVertLabelsLegacy
const label globalPointOffset
)
{
if (!globalPointOffset)
{
return vertLabels;
}
labelList output(vertLabels);
renumberVertLabelsLegacy(output, globalPointOffset);
if (globalPointOffset)
{
renumberVertLabelsLegacy(output, globalPointOffset);
}
return output;
}
@ -863,13 +862,12 @@ Foam::labelList Foam::vtk::vtuSizing::copyVertLabelsXml
const label globalPointOffset
)
{
if (!globalPointOffset)
{
return vertLabels;
}
labelList output(vertLabels);
renumberVertLabelsXml(output, globalPointOffset);
if (globalPointOffset)
{
renumberVertLabelsXml(output, globalPointOffset);
}
return output;
}
@ -902,13 +900,12 @@ Foam::labelList Foam::vtk::vtuSizing::copyFaceLabelsXml
const label globalPointOffset
)
{
if (!globalPointOffset)
{
return faceLabels;
}
labelList output(faceLabels);
renumberFaceLabelsXml(output, globalPointOffset);
if (globalPointOffset)
{
renumberFaceLabelsXml(output, globalPointOffset);
}
return output;
}
@ -957,13 +954,12 @@ Foam::labelList Foam::vtk::vtuSizing::copyFaceOffsetsXml
const label prevOffset
)
{
if (!prevOffset)
{
return faceOffsets;
}
labelList output(faceOffsets);
renumberFaceOffsetsXml(output, prevOffset);
if (prevOffset)
{
renumberFaceOffsetsXml(output, prevOffset);
}
return output;
}

View File

@ -566,7 +566,8 @@ Foam::wordList Foam::vtkUnstructuredReader::readFieldArray
);
fields.append(arrayName);
}
return fields.shrink();
return wordList(std::move(fields));
}

View File

@ -78,7 +78,7 @@ Foam::labelList Foam::functionObjects::vtkWrite::getSelectedPatches
}
}
return patchIDs.shrink();
return labelList(std::move(patchIDs));
}

View File

@ -137,7 +137,7 @@ Foam::lumpedPointDisplacementPointPatchVectorField::patchIds
}
}
return patchLst.shrink();
return labelList(std::move(patchLst));
}

View File

@ -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;
}

View File

@ -3995,7 +3995,8 @@ Foam::labelList Foam::meshRefinement::freeStandingBaffleFaces
}
}
}
return faceLabels.shrink();
return labelList(std::move(faceLabels));
}

View File

@ -677,7 +677,8 @@ Foam::List<Foam::labelPair> Foam::localPointRegion::findDuplicateFacePairs
}
}
}
return baffles.shrink();
return List<labelPair>(std::move(baffles));
}

View File

@ -1113,7 +1113,7 @@ Foam::labelList Foam::surfaceFeatures::selectFeatureEdges
}
}
return selectedEdges.shrink();
return labelList(std::move(selectedEdges));
}

View File

@ -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_()
{

View File

@ -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, "")

View File

@ -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

View File

@ -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)

View File

@ -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()

View File

@ -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, "")

View File

@ -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, "")

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)