diff --git a/lib/token.h b/lib/token.h index edad3606f..42912d065 100644 --- a/lib/token.h +++ b/lib/token.h @@ -117,6 +117,9 @@ struct TokenImpl { }; struct CppcheckAttributes *mCppcheckAttributes; + // For memoization, to speed up parsing of huge arrays #8897 + enum class Cpp11init {UNKNOWN, CPP11INIT, NOINIT} mCpp11init; + void setCppcheckAttribute(CppcheckAttributes::Type type, MathLib::bigint value); bool getCppcheckAttribute(CppcheckAttributes::Type type, MathLib::bigint *value) const; @@ -139,6 +142,7 @@ struct TokenImpl { , mTemplateSimplifierPointers() , mScopeInfo(nullptr) , mCppcheckAttributes(nullptr) + , mCpp11init(Cpp11init::UNKNOWN) {} ~TokenImpl(); @@ -1220,6 +1224,9 @@ public: void scopeInfo(std::shared_ptr newScopeInfo); std::shared_ptr scopeInfo() const; + + void setCpp11init(bool cpp11init) const { mImpl->mCpp11init=cpp11init ? TokenImpl::Cpp11init::CPP11INIT : TokenImpl::Cpp11init::NOINIT; } + TokenImpl::Cpp11init isCpp11init() const { return mImpl->mCpp11init; } }; /// @} diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index dfe6684ef..81c556921 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -540,10 +540,20 @@ static Token * findCppTypeInitPar(Token *tok) } // X{} X{} etc +static bool iscpp11init_impl(const Token * const tok); static bool iscpp11init(const Token * const tok) +{ + if (tok->isCpp11init() == TokenImpl::Cpp11init::UNKNOWN) + tok->setCpp11init(iscpp11init_impl(tok)); + return tok->isCpp11init() == TokenImpl::Cpp11init::CPP11INIT; +} + +static bool iscpp11init_impl(const Token * const tok) { const Token *nameToken = tok; while (nameToken && nameToken->str() == "{") { + if(nameToken->isCpp11init() != TokenImpl::Cpp11init::UNKNOWN) + return nameToken->isCpp11init() == TokenImpl::Cpp11init::CPP11INIT; nameToken = nameToken->previous(); if (nameToken && nameToken->str() == "," && Token::simpleMatch(nameToken->previous(), "} ,")) nameToken = nameToken->linkAt(-1);