diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 6c4697e7ed..d5815133b5 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -28,7 +28,6 @@ License #include "dictionaryEntry.H" #include "regExp.H" #include "OSHA1stream.H" -#include "DynamicList.H" /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */ @@ -214,22 +213,20 @@ Foam::SHA1Digest Foam::dictionary::digest() const Foam::tokenList Foam::dictionary::tokens() const { - // Serialize dictionary into a string + // Serialize dictionary entries into a string OStringStream os; - write(os, false); - IStringStream is(os.str()); - - DynamicList tokens; - - // Parse string as tokens - token tok; - while (is.read(tok)) + // Process entries + forAllConstIter(parent_type, *this, iter) { - tokens.append(std::move(tok)); + os << *iter; } - return tokenList(tokens.xfer()); + // String re-parsed as a list of tokens + return static_cast + ( + ITstream("tokens", os.str(), os.format(), os.version()) + ); } diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C index 76a0c482c4..1202375bd1 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C @@ -30,24 +30,23 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::primitiveEntry::appendTokenList(const UList& varTokens) +void Foam::primitiveEntry::appendTokenList(const UList& toks) { - for (const token& tok : varTokens) + for (const token& tok : toks) { - newElmt(tokenIndex()++) = tok; // append copy + newElmt(tokenIndex()++) = tok; // copy append } } -void Foam::primitiveEntry::appendTokensFromString(const string& input) +void Foam::primitiveEntry::appendTokenList(List&& toks) { - IStringStream is(input); - - token tok; - while (!is.read(tok).bad() && tok.good()) + for (token& tok : toks) { - newElmt(tokenIndex()++) = std::move(tok); + newElmt(tokenIndex()++) = std::move(tok); // move append } + + toks.clear(); } @@ -97,13 +96,16 @@ bool Foam::primitiveEntry::expandVariable return false; } - // Split input string into a stream of tokens and append to list - appendTokensFromString(str); + // String parsed as a list of tokens + ITstream its("env", str); + appendTokenList(std::move(static_cast(its))); } else if (eptr->isDict()) { // Found dictionary entry - appendTokenList(eptr->dict().tokens()); + + tokenList toks(eptr->dict().tokens().xfer()); + appendTokenList(std::move(toks)); } else { diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H index 59c2a75734..c035f4451a 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H @@ -73,14 +73,13 @@ class primitiveEntry Istream& is ); - //- Append the given tokens at the current tokenIndex + //- Copy append the given tokens at the current tokenIndex // No filtering on the tokens. - void appendTokenList(const UList& varTokens); + void appendTokenList(const UList& toks); - //- Split input string into a stream of tokens and append at the - //- current tokenIndex. + //- Move append the given tokens at the current tokenIndex // No filtering on the tokens. - void appendTokensFromString(const string& input); + void appendTokenList(List&& toks); //- Expand the given variable.