From db1c1e89bed0745a4828fe0cc016b63f47a30c2e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 26 Jan 2018 12:50:06 +0100 Subject: [PATCH] ENH: avoid xfer on simple data types - in many places can use move construcors or rely on RVO --- applications/test/fileName/Test-fileName.C | 132 +++++++++--------- .../test/fileNameClean/Test-fileNameClean.C | 3 + .../masterUncollatedFileOperation.C | 2 +- src/OpenFOAM/meshes/meshShapes/cell/cell.H | 6 +- src/OpenFOAM/meshes/meshShapes/cell/cellI.H | 4 +- src/OpenFOAM/meshes/meshShapes/face/face.C | 19 +-- src/OpenFOAM/meshes/meshShapes/face/face.H | 11 +- src/OpenFOAM/meshes/meshShapes/face/faceI.H | 6 - .../polyMesh/globalMeshData/globalIndex.C | 6 - .../polyMesh/globalMeshData/globalIndex.H | 10 +- .../polyMesh/globalMeshData/globalIndexI.H | 8 +- .../polyMesh/globalMeshData/globalMeshData.C | 3 +- .../primitives/strings/fileName/fileName.C | 36 ++--- src/conversion/polyDualMesh/polyDualMesh.C | 20 +-- .../potential/potential/potential.C | 2 +- src/meshTools/regionSplit/regionSplit.C | 4 +- .../searchableSurfaceCollection.C | 4 +- .../distributedTriSurfaceMesh.C | 10 +- 18 files changed, 134 insertions(+), 152 deletions(-) diff --git a/applications/test/fileName/Test-fileName.C b/applications/test/fileName/Test-fileName.C index 3863a698f8..42b3fe4d7a 100644 --- a/applications/test/fileName/Test-fileName.C +++ b/applications/test/fileName/Test-fileName.C @@ -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 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(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 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(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 diff --git a/applications/test/fileNameClean/Test-fileNameClean.C b/applications/test/fileNameClean/Test-fileNameClean.C index 47e3572894..e87636cc7d 100644 --- a/applications/test/fileNameClean/Test-fileNameClean.C +++ b/applications/test/fileNameClean/Test-fileNameClean.C @@ -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 diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C index 44604a64f5..298f6ae7ff 100644 --- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C @@ -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); diff --git a/src/OpenFOAM/meshes/meshShapes/cell/cell.H b/src/OpenFOAM/meshes/meshShapes/cell/cell.H index 6db36cdfb1..b1269443f3 100644 --- a/src/OpenFOAM/meshes/meshShapes/cell/cell.H +++ b/src/OpenFOAM/meshes/meshShapes/cell/cell.H @@ -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& lst); + //- Move construct from list of labels + explicit inline cell(labelList&& lst); //- Construct from Istream inline cell(Istream& is); diff --git a/src/OpenFOAM/meshes/meshShapes/cell/cellI.H b/src/OpenFOAM/meshes/meshShapes/cell/cellI.H index 0c31f8e99b..e438ec80dd 100644 --- a/src/OpenFOAM/meshes/meshShapes/cell/cellI.H +++ b/src/OpenFOAM/meshes/meshShapes/cell/cellI.H @@ -41,9 +41,9 @@ inline Foam::cell::cell(const labelUList& lst) {} -inline Foam::cell::cell(const Xfer& lst) +inline Foam::cell::cell(labelList&& lst) : - labelList(lst) + labelList(std::move(lst)) {} diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index 6f44cb0314..c1232819b4 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -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) { diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index 0866a7eead..fc0069f192 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -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 explicit inline face(const FixedList& lst); - //- Construct from an initializer list of labels + //- Copy construct from an initializer list of labels explicit inline face(std::initializer_list