ENH: add move/swap semantics to string types and regExp

- move append() single element to List and DynamicList

ENH: add stringOps::count to avoid unnecessary string conversions
This commit is contained in:
Mark Olesen
2017-11-05 13:26:10 +01:00
parent cae8a894cd
commit e1b71c028c
24 changed files with 525 additions and 122 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -44,7 +44,7 @@ int main(int argc, char *argv[])
Info<< "Test expressions:" << rawList << endl;
IOobject::writeDivider(Info) << endl;
List<string> groups;
List<std::string> groups;
// Report matches:
forAll(rawList, elemI)
@ -74,7 +74,23 @@ int main(int argc, char *argv[])
Info<< "false";
}
}
Info<< endl;
if (false)
{
regExp re2(std::move(re));
Info<<"move construct: " << re.exists() << "/" << re2.exists()
<< endl;
re = std::move(re2);
Info<<"move assign: " << re.exists() << "/" << re2.exists()
<< endl;
re.swap(re2);
Info<<"swap: " << re.exists() << "/" << re2.exists()
<< endl;
}
}
Info<< nl << "test regExp(const char*) ..." << endl;

View File

@ -69,6 +69,65 @@ int main(int argc, char *argv[])
Info<<"trimRight: " << stringOps::trimRight(test) << endl;
Info<<"trim: " << stringOps::trim(test) << endl;
if (false)
{
Info<<"test move construct - string size:" << test.size() << nl;
string test2(std::move(test));
Info<<"input size:" << test.size() << nl;
Info<<"moved size:" << test2.size() << nl;
Info<<"test move assign - string sizes:"
<< test.size() << "/" << test2.size() << nl;
test = std::move(test2);
Info<<"input size:" << test.size() << nl;
Info<<"moved size:" << test2.size() << nl;
}
if (false)
{
std::string str("some text");
Info<<"test move construct to string:" << str.size() << nl;
Foam::string test2(std::move(str));
Info<<"input/moved sizes:" << str.size() << "/" << test2.size() << nl;
str = std::move(test2);
Info<<"test move assign - sizes:"
<< str.size() << "/" << test2.size() << nl;
}
if (false)
{
Foam::string str("thisIsAWord");
Info<<"test move construct to word:" << str.size() << nl;
word test2(std::move(str));
Info<<"input/moved sizes:" << str.size() << "/" << test2.size() << nl;
str = std::move(test2);
Info<<"test move assign - sizes:"
<< str.size() << "/" << test2.size() << nl;
// move back
test2.swap(str);
Info<<"test move assign - sizes:"
<< str.size() << "/" << test2.size() << nl;
string str2(std::move(test2));
Info<<"input/moved sizes:" << test2.size() << "/" << str2.size() << nl;
}
{
fileName test1("libFooBar.so");

View File

@ -56,6 +56,56 @@ int main(int argc, char *argv[])
{"file[a-b]", wordRe::REGEX},
};
if (true)
{
Info<<"keyType: " << keyre << endl;
keyType key2(std::move(keyre));
Info<<"move construct: <" << keyre << "> <" << key2 << ">" << endl;
keyre = std::move(key2);
Info<<"move assign: <" << keyre << "> <" << key2 << ">" << endl;
keyType key3;
keyre.swap(key3);
Info<<"swap: <" << keyre << "> <" << key3 << ">" << endl;
keyre = std::move(key3);
Info<<"move assign: <" << keyre << "> <" << key3 << ">" << endl;
return 0;
}
if (false)
{
wordRe keyre("y.*", wordRe::REGEX);
Info<<"wordRe: " << keyre << endl;
wordRe key2(std::move(keyre));
Info<<"keyTypes: " << keyre << " " << key2 << endl;
keyre = std::move(key2);
Info<<"keyTypes: " << keyre << " " << key2 << endl;
wordRe key3;
keyre.swap(key3);
Info<<"keyTypes: <" << keyre << "> <" << key3 << ">" << endl;
keyre = std::move(key3);
Info<<"keyTypes: <" << keyre << "> <" << key3 << ">" << endl;
return 0;
}
wordRes wrelist(wordrelist);
Info<< "re-list:" << wrelist() << endl;
@ -76,7 +126,7 @@ int main(int argc, char *argv[])
wre = "this .* file";
Info<<"substring: " << wre(4) << endl;
Info<<"substring: " << wre.substr(4) << endl;
wre.info(Info) << endl;
wre = s1;