mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: avoid xfer on simple data types
- in many places can use move construcors or rely on RVO
This commit is contained in:
@ -194,6 +194,7 @@ int main(int argc, char *argv[])
|
||||
argList::addBoolOption("ext", "test handing of file extensions");
|
||||
argList::addBoolOption("construct", "test constructors");
|
||||
argList::addBoolOption("relative", "test relative operations");
|
||||
argList::addBoolOption("system", "test filesystem operations");
|
||||
argList::addBoolOption("default", "reinstate default tests");
|
||||
argList::addNote("runs default tests or specified ones only");
|
||||
|
||||
@ -485,72 +486,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
if (!defaultTests)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
DynamicList<word> wrdList
|
||||
{
|
||||
"hello",
|
||||
"hello1",
|
||||
"hello2",
|
||||
"hello3",
|
||||
"hello4.hmm"
|
||||
};
|
||||
|
||||
fileName pathName(wrdList);
|
||||
|
||||
Info<< "pathName = " << pathName << nl
|
||||
<< "pathName.name() = >" << pathName.name() << "<\n"
|
||||
<< "pathName.path() = " << pathName.path() << nl
|
||||
<< "pathName.ext() = >" << pathName.ext() << "<\n"
|
||||
<< "pathName.name(true) = >" << pathName.name(true) << "<\n";
|
||||
|
||||
Info<< "pathName.components() = " << pathName.components() << nl
|
||||
<< "pathName.component(2) = " << pathName.component(2) << nl
|
||||
<< endl;
|
||||
|
||||
// try with different combination
|
||||
// The final one should emit warnings
|
||||
for (label start = 0; start <= wrdList.size(); ++start)
|
||||
{
|
||||
fileName instance, local;
|
||||
word name;
|
||||
|
||||
fileName path(SubList<word>(wrdList, wrdList.size()-start, start));
|
||||
fileName path2 = "."/path;
|
||||
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobject::fileNameComponents for " << path << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path2,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobject::fileNameComponents for " << path2 << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Test some copying and deletion
|
||||
if (args.found("system"))
|
||||
{
|
||||
const fileName dirA("dirA");
|
||||
const fileName lnA("lnA");
|
||||
@ -663,6 +600,71 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
if (!defaultTests)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
DynamicList<word> wrdList
|
||||
{
|
||||
"hello",
|
||||
"hello1",
|
||||
"hello2",
|
||||
"hello3",
|
||||
"hello4.hmm"
|
||||
};
|
||||
|
||||
fileName pathName(wrdList);
|
||||
|
||||
Info<< "pathName = " << pathName << nl
|
||||
<< "pathName.name() = >" << pathName.name() << "<\n"
|
||||
<< "pathName.path() = " << pathName.path() << nl
|
||||
<< "pathName.ext() = >" << pathName.ext() << "<\n"
|
||||
<< "pathName.name(true) = >" << pathName.name(true) << "<\n";
|
||||
|
||||
Info<< "pathName.components() = " << pathName.components() << nl
|
||||
<< "pathName.component(2) = " << pathName.component(2) << nl
|
||||
<< endl;
|
||||
|
||||
// try with different combination
|
||||
// The final one should emit warnings
|
||||
for (label start = 0; start <= wrdList.size(); ++start)
|
||||
{
|
||||
fileName instance, local;
|
||||
word name;
|
||||
|
||||
fileName path(SubList<word>(wrdList, wrdList.size()-start, start));
|
||||
fileName path2 = "."/path;
|
||||
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobject::fileNameComponents for " << path << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path2,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobject::fileNameComponents for " << path2 << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// test findEtcFile
|
||||
Info<< "\n\nfindEtcFile tests:" << nl
|
||||
<< " controlDict => " << findEtcFile("controlDict") << nl
|
||||
|
||||
@ -46,6 +46,9 @@ void printCleaning(fileName& pathName)
|
||||
<< " name() = " << pathName.name() << nl
|
||||
<< " joined = " << pathName.path()/pathName.name() << nl << nl;
|
||||
|
||||
Info<< "components = " << flatOutput(pathName.components()) << nl;
|
||||
Info<< "component 2 = " << pathName.component(2) << nl;
|
||||
|
||||
pathName.clean();
|
||||
|
||||
Info<< "cleaned = " << pathName << nl
|
||||
|
||||
@ -1458,7 +1458,7 @@ Foam::instantList Foam::fileOperations::masterUncollatedFileOperation::findTimes
|
||||
}
|
||||
Pstream::scatter(times);
|
||||
|
||||
instantList* tPtr = new instantList(times.xfer());
|
||||
instantList* tPtr = new instantList(std::move(times));
|
||||
|
||||
times_.insert(directory, tPtr);
|
||||
|
||||
|
||||
@ -69,11 +69,11 @@ public:
|
||||
//- Construct given size, with invalid point labels (-1)
|
||||
explicit inline cell(const label sz);
|
||||
|
||||
//- Construct from list of labels
|
||||
//- Copy construct from list of labels
|
||||
explicit inline cell(const labelUList& lst);
|
||||
|
||||
//- Construct by transferring list of labels
|
||||
explicit inline cell(const Xfer<labelList>& lst);
|
||||
//- Move construct from list of labels
|
||||
explicit inline cell(labelList&& lst);
|
||||
|
||||
//- Construct from Istream
|
||||
inline cell(Istream& is);
|
||||
|
||||
@ -41,9 +41,9 @@ inline Foam::cell::cell(const labelUList& lst)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::cell::cell(const Xfer<labelList>& lst)
|
||||
inline Foam::cell::cell(labelList&& lst)
|
||||
:
|
||||
labelList(lst)
|
||||
labelList(std::move(lst))
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -606,23 +606,26 @@ Foam::face Foam::face::reverseFace() const
|
||||
// Reverse the label list and return
|
||||
// The starting points of the original and reverse face are identical.
|
||||
|
||||
const labelList& f = *this;
|
||||
labelList newList(size());
|
||||
const labelUList& origFace = *this;
|
||||
const label len = origFace.size();
|
||||
|
||||
newList[0] = f[0];
|
||||
|
||||
for (label pointi = 1; pointi < newList.size(); pointi++)
|
||||
face newFace(len);
|
||||
if (len)
|
||||
{
|
||||
newList[pointi] = f[size() - pointi];
|
||||
newFace[0] = origFace[0];
|
||||
for (label i=1; i < len; ++i)
|
||||
{
|
||||
newFace[i] = origFace[len - i];
|
||||
}
|
||||
}
|
||||
|
||||
return face(xferMove(newList));
|
||||
return newFace;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::face::which(const label globalIndex) const
|
||||
{
|
||||
const labelList& f = *this;
|
||||
const labelUList& f = *this;
|
||||
|
||||
forAll(f, localIdx)
|
||||
{
|
||||
|
||||
@ -150,20 +150,17 @@ public:
|
||||
//- Construct given size, with invalid point labels (-1)
|
||||
explicit inline face(const label sz);
|
||||
|
||||
//- Construct from list of labels
|
||||
//- Copy construct from list of labels
|
||||
explicit inline face(const labelUList& lst);
|
||||
|
||||
//- Construct from list of labels
|
||||
//- Copy construct from list of labels
|
||||
template<unsigned Size>
|
||||
explicit inline face(const FixedList<label, Size>& lst);
|
||||
|
||||
//- Construct from an initializer list of labels
|
||||
//- Copy construct from an initializer list of labels
|
||||
explicit inline face(std::initializer_list<label> lst);
|
||||
|
||||
//- Transfer (move) construct
|
||||
explicit inline face(const Xfer<labelList>& lst);
|
||||
|
||||
//- Move construct
|
||||
//- Move construct from list of labels
|
||||
explicit inline face(labelList&& lst);
|
||||
|
||||
//- Copy construct from triFace
|
||||
|
||||
@ -70,12 +70,6 @@ inline Foam::face::face(std::initializer_list<label> lst)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::face::face(const Xfer<labelList>& lst)
|
||||
:
|
||||
labelList(lst)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::face::face(labelList&& lst)
|
||||
:
|
||||
labelList(std::move(lst))
|
||||
|
||||
@ -94,12 +94,6 @@ Foam::globalIndex::globalIndex(const label localSize)
|
||||
}
|
||||
|
||||
|
||||
Foam::globalIndex::globalIndex(const labelList& offsets)
|
||||
:
|
||||
offsets_(offsets)
|
||||
{}
|
||||
|
||||
|
||||
Foam::globalIndex::globalIndex(Istream& is)
|
||||
{
|
||||
is >> offsets_;
|
||||
|
||||
@ -74,7 +74,7 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline globalIndex();
|
||||
globalIndex() = default;
|
||||
|
||||
//- Construct from local max size. Does communication with default
|
||||
// communicator and message tag.
|
||||
@ -90,11 +90,11 @@ public:
|
||||
const bool parallel // use parallel comms
|
||||
);
|
||||
|
||||
//- Construct from components
|
||||
globalIndex(const labelList& offsets);
|
||||
//- Copy construct from list of labels
|
||||
inline globalIndex(const labelUList& offsets);
|
||||
|
||||
//- Construct from components
|
||||
inline globalIndex(const Xfer<labelList>& offsets);
|
||||
//- Move construct from list of labels
|
||||
inline globalIndex(labelList&& offsets);
|
||||
|
||||
//- Construct from Istream
|
||||
globalIndex(Istream& is);
|
||||
|
||||
@ -27,13 +27,15 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::globalIndex::globalIndex()
|
||||
inline Foam::globalIndex::globalIndex(const labelUList& offsets)
|
||||
:
|
||||
offsets_(offsets)
|
||||
{}
|
||||
|
||||
|
||||
Foam::globalIndex::globalIndex(const Xfer<labelList>& offsets)
|
||||
inline Foam::globalIndex::globalIndex(labelList&& offsets)
|
||||
:
|
||||
offsets_(offsets)
|
||||
offsets_(std::move(offsets))
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -1545,9 +1545,8 @@ void Foam::globalMeshData::calcGlobalPointBoundaryCells() const
|
||||
}
|
||||
|
||||
|
||||
boundaryCellsPtr_.reset(new labelList());
|
||||
boundaryCellsPtr_.reset(new labelList(std::move(cellMap)));
|
||||
labelList& boundaryCells = boundaryCellsPtr_();
|
||||
boundaryCells.transfer(cellMap.shrink());
|
||||
|
||||
|
||||
// Convert point-cells to global (boundary)cell numbers
|
||||
|
||||
@ -29,6 +29,7 @@ License
|
||||
#include "OSspecific.H"
|
||||
#include "wordRe.H"
|
||||
#include "fileOperation.H"
|
||||
#include "stringOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -463,28 +464,20 @@ bool Foam::fileName::hasExt(const wordRe& ending) const
|
||||
|
||||
Foam::wordList Foam::fileName::components(const char delimiter) const
|
||||
{
|
||||
DynamicList<word> wrdList(20);
|
||||
const auto parsed = stringOps::split<string>(*this, delimiter);
|
||||
|
||||
size_type beg=0, end=0;
|
||||
wordList words(parsed.size());
|
||||
|
||||
while ((end = find(delimiter, beg)) != npos)
|
||||
label i = 0;
|
||||
for (const auto& sub : parsed)
|
||||
{
|
||||
// Avoid empty element (caused by doubled slashes)
|
||||
if (beg < end)
|
||||
{
|
||||
wrdList.append(substr(beg, end-beg));
|
||||
}
|
||||
beg = end + 1;
|
||||
// Could easily filter out '.' here too
|
||||
words[i] = sub.str();
|
||||
++i;
|
||||
}
|
||||
|
||||
// Avoid empty trailing element
|
||||
if (beg < size())
|
||||
{
|
||||
wrdList.append(substr(beg));
|
||||
}
|
||||
|
||||
// Transfer to wordList
|
||||
return wordList(wrdList.xfer());
|
||||
// As a plain wordList
|
||||
return words;
|
||||
}
|
||||
|
||||
|
||||
@ -494,7 +487,14 @@ Foam::word Foam::fileName::component
|
||||
const char delimiter
|
||||
) const
|
||||
{
|
||||
return components(delimiter)[cmpt];
|
||||
const auto parsed = stringOps::split<string>(*this, delimiter);
|
||||
|
||||
if (cmpt < parsed.size())
|
||||
{
|
||||
return parsed[cmpt].str();
|
||||
}
|
||||
|
||||
return word();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -545,8 +545,6 @@ void Foam::polyDualMesh::splitFace
|
||||
if (subFace.size() > 2)
|
||||
{
|
||||
// Enough vertices to create a face from.
|
||||
subFace.shrink();
|
||||
|
||||
dualFaces.append(face(subFace));
|
||||
dualOwner.append(meshPointi);
|
||||
dualNeighbour.append(-1);
|
||||
@ -559,8 +557,6 @@ void Foam::polyDualMesh::splitFace
|
||||
if (subFace.size() > 2)
|
||||
{
|
||||
// Enough vertices to create a face from.
|
||||
subFace.shrink();
|
||||
|
||||
dualFaces.append(face(subFace));
|
||||
dualOwner.append(meshPointi);
|
||||
dualNeighbour.append(-1);
|
||||
@ -1194,18 +1190,10 @@ void Foam::polyDualMesh::calcDual
|
||||
|
||||
// Transfer face info to straight lists
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
faceList dualFaces(dynDualFaces.shrink(), true);
|
||||
dynDualFaces.clear();
|
||||
|
||||
labelList dualOwner(dynDualOwner.shrink(), true);
|
||||
dynDualOwner.clear();
|
||||
|
||||
labelList dualNeighbour(dynDualNeighbour.shrink(), true);
|
||||
dynDualNeighbour.clear();
|
||||
|
||||
labelList dualRegion(dynDualRegion.shrink(), true);
|
||||
dynDualRegion.clear();
|
||||
|
||||
faceList dualFaces(std::move(dynDualFaces));
|
||||
labelList dualOwner(std::move(dynDualOwner));
|
||||
labelList dualNeighbour(std::move(dynDualNeighbour));
|
||||
labelList dualRegion(std::move(dynDualRegion));
|
||||
|
||||
|
||||
// Dump faces.
|
||||
|
||||
@ -89,7 +89,7 @@ void Foam::potential::setSiteIdList(const dictionary& moleculePropertiesDict)
|
||||
}
|
||||
}
|
||||
|
||||
siteIdList_.transfer(pairPotentialSiteIdList.shrink());
|
||||
siteIdList_.transfer(pairPotentialSiteIdList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -172,7 +172,7 @@ Foam::autoPtr<Foam::globalIndex> Foam::regionSplit::calcRegionSplit
|
||||
{
|
||||
offsets[i] = mesh().nFaces();
|
||||
}
|
||||
const globalIndex globalRegions(offsets.xfer());
|
||||
const globalIndex globalRegions(std::move(offsets));
|
||||
|
||||
// Minimise regions across connected cells
|
||||
// Note: still uses global decisions so all processors are running
|
||||
@ -215,7 +215,7 @@ Foam::autoPtr<Foam::globalIndex> Foam::regionSplit::calcRegionSplit
|
||||
compactOffsets[i] = globalToCompact.size();
|
||||
}
|
||||
|
||||
return autoPtr<globalIndex>(new globalIndex(compactOffsets.xfer()));
|
||||
return autoPtr<globalIndex>(new globalIndex(std::move(compactOffsets)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -285,7 +285,7 @@ Foam::searchableSurfaceCollection::~searchableSurfaceCollection()
|
||||
|
||||
const Foam::wordList& Foam::searchableSurfaceCollection::regions() const
|
||||
{
|
||||
if (regions_.size() == 0)
|
||||
if (regions_.empty())
|
||||
{
|
||||
regionOffset_.setSize(subGeom_.size());
|
||||
|
||||
@ -309,7 +309,7 @@ const Foam::wordList& Foam::searchableSurfaceCollection::regions() const
|
||||
}
|
||||
}
|
||||
}
|
||||
regions_.transfer(allRegions.shrink());
|
||||
regions_.transfer(allRegions);
|
||||
}
|
||||
return regions_;
|
||||
}
|
||||
|
||||
@ -298,8 +298,8 @@ Foam::distributedTriSurfaceMesh::distributeSegments
|
||||
sendMap[proci].transfer(dynSendMap[proci]);
|
||||
}
|
||||
|
||||
allSegments.transfer(dynAllSegments.shrink());
|
||||
allSegmentMap.transfer(dynAllSegmentMap.shrink());
|
||||
allSegments.transfer(dynAllSegments);
|
||||
allSegmentMap.transfer(dynAllSegmentMap);
|
||||
}
|
||||
|
||||
|
||||
@ -743,9 +743,9 @@ Foam::distributedTriSurfaceMesh::calcLocalQueries
|
||||
sendMap[proci].transfer(dynSendMap[proci]);
|
||||
}
|
||||
|
||||
allCentres.transfer(dynAllCentres.shrink());
|
||||
allRadiusSqr.transfer(dynAllRadiusSqr.shrink());
|
||||
allSegmentMap.transfer(dynAllSegmentMap.shrink());
|
||||
allCentres.transfer(dynAllCentres);
|
||||
allRadiusSqr.transfer(dynAllRadiusSqr);
|
||||
allSegmentMap.transfer(dynAllSegmentMap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user