Optimization: Reduced memory consumption of token list
- allocate memory for mTemplateSimplifierPointers only if necessary - reordered member variables in TokenImpl
This commit is contained in:
parent
c409daf918
commit
ade253a730
|
@ -195,8 +195,8 @@ TemplateSimplifier::TokenAndName::TokenAndName(const TokenAndName& other) :
|
|||
|
||||
TemplateSimplifier::TokenAndName::~TokenAndName()
|
||||
{
|
||||
if (mToken)
|
||||
mToken->templateSimplifierPointers().erase(this);
|
||||
if (mToken && mToken->templateSimplifierPointers())
|
||||
mToken->templateSimplifierPointers()->erase(this);
|
||||
}
|
||||
|
||||
const Token * TemplateSimplifier::TokenAndName::aliasStartToken() const
|
||||
|
@ -3107,12 +3107,12 @@ void TemplateSimplifier::replaceTemplateUsage(
|
|||
Token::Match(nameTok, "template|const_cast|dynamic_cast|reinterpret_cast|static_cast"))
|
||||
continue;
|
||||
|
||||
std::set<TemplateSimplifier::TokenAndName*> & pointers = nameTok->templateSimplifierPointers();
|
||||
std::set<TemplateSimplifier::TokenAndName*>* pointers = nameTok->templateSimplifierPointers();
|
||||
|
||||
// check if instantiation matches token instantiation from pointer
|
||||
if (pointers.size()) {
|
||||
if (pointers && pointers->size()) {
|
||||
// check full name
|
||||
if (instantiation.fullName() != (*pointers.begin())->fullName()) {
|
||||
if (instantiation.fullName() != (*pointers->begin())->fullName()) {
|
||||
// FIXME: fallback to just matching name
|
||||
if (nameTok->str() != instantiation.name())
|
||||
continue;
|
||||
|
@ -3173,7 +3173,7 @@ void TemplateSimplifier::replaceTemplateUsage(
|
|||
nameTok->str(newName);
|
||||
|
||||
for (Token *tok = nameTok1->next(); tok != tok2; tok = tok->next()) {
|
||||
if (tok->isName() && !tok->templateSimplifierPointers().empty()) {
|
||||
if (tok->isName() && tok->templateSimplifierPointers() && !tok->templateSimplifierPointers()->empty()) {
|
||||
std::list<TokenAndName>::iterator ti;
|
||||
for (ti = mTemplateInstantiations.begin(); ti != mTemplateInstantiations.end();) {
|
||||
if (ti->token() == tok) {
|
||||
|
|
|
@ -251,13 +251,15 @@ void Token::swapWithNext()
|
|||
std::swap(mTokType, mNext->mTokType);
|
||||
std::swap(mFlags, mNext->mFlags);
|
||||
std::swap(mImpl, mNext->mImpl);
|
||||
for (auto *templateSimplifierPointer : mImpl->mTemplateSimplifierPointers) {
|
||||
templateSimplifierPointer->token(this);
|
||||
}
|
||||
if (mImpl->mTemplateSimplifierPointers)
|
||||
for (auto *templateSimplifierPointer : *mImpl->mTemplateSimplifierPointers) {
|
||||
templateSimplifierPointer->token(this);
|
||||
}
|
||||
|
||||
for (auto *templateSimplifierPointer : mNext->mImpl->mTemplateSimplifierPointers) {
|
||||
templateSimplifierPointer->token(mNext);
|
||||
}
|
||||
if (mNext->mImpl->mTemplateSimplifierPointers)
|
||||
for (auto *templateSimplifierPointer : *mNext->mImpl->mTemplateSimplifierPointers) {
|
||||
templateSimplifierPointer->token(mNext);
|
||||
}
|
||||
if (mNext->mLink)
|
||||
mNext->mLink->mLink = this;
|
||||
if (this->mLink)
|
||||
|
@ -274,9 +276,10 @@ void Token::takeData(Token *fromToken)
|
|||
delete mImpl;
|
||||
mImpl = fromToken->mImpl;
|
||||
fromToken->mImpl = nullptr;
|
||||
for (auto *templateSimplifierPointer : mImpl->mTemplateSimplifierPointers) {
|
||||
templateSimplifierPointer->token(this);
|
||||
}
|
||||
if (mImpl->mTemplateSimplifierPointers)
|
||||
for (auto *templateSimplifierPointer : *mImpl->mTemplateSimplifierPointers) {
|
||||
templateSimplifierPointer->token(this);
|
||||
}
|
||||
mLink = fromToken->mLink;
|
||||
if (mLink)
|
||||
mLink->link(this);
|
||||
|
@ -2211,9 +2214,11 @@ TokenImpl::~TokenImpl()
|
|||
delete mValueType;
|
||||
delete mValues;
|
||||
|
||||
for (auto *templateSimplifierPointer : mTemplateSimplifierPointers) {
|
||||
templateSimplifierPointer->token(nullptr);
|
||||
}
|
||||
if (mTemplateSimplifierPointers)
|
||||
for (auto *templateSimplifierPointer : *mTemplateSimplifierPointers) {
|
||||
templateSimplifierPointer->token(nullptr);
|
||||
}
|
||||
delete mTemplateSimplifierPointers;
|
||||
|
||||
while (mCppcheckAttributes) {
|
||||
struct CppcheckAttributes *c = mCppcheckAttributes;
|
||||
|
|
18
lib/token.h
18
lib/token.h
|
@ -99,11 +99,8 @@ struct TokenImpl {
|
|||
std::list<ValueFlow::Value>* mValues;
|
||||
static const std::list<ValueFlow::Value> mEmptyValueList;
|
||||
|
||||
/** Bitfield bit count. */
|
||||
unsigned char mBits;
|
||||
|
||||
// Pointer to a template in the template simplifier
|
||||
std::set<TemplateSimplifier::TokenAndName*> mTemplateSimplifierPointers;
|
||||
std::set<TemplateSimplifier::TokenAndName*>* mTemplateSimplifierPointers;
|
||||
|
||||
// Pointer to the object representing this token's scope
|
||||
std::shared_ptr<ScopeInfo2> mScopeInfo;
|
||||
|
@ -119,6 +116,9 @@ struct TokenImpl {
|
|||
// For memoization, to speed up parsing of huge arrays #8897
|
||||
enum class Cpp11init {UNKNOWN, CPP11INIT, NOINIT} mCpp11init;
|
||||
|
||||
/** Bitfield bit count. */
|
||||
unsigned char mBits;
|
||||
|
||||
void setCppcheckAttribute(CppcheckAttributes::Type type, MathLib::bigint value);
|
||||
bool getCppcheckAttribute(CppcheckAttributes::Type type, MathLib::bigint *value) const;
|
||||
|
||||
|
@ -137,11 +137,11 @@ struct TokenImpl {
|
|||
, mOriginalName(nullptr)
|
||||
, mValueType(nullptr)
|
||||
, mValues(nullptr)
|
||||
, mBits(0)
|
||||
, mTemplateSimplifierPointers()
|
||||
, mTemplateSimplifierPointers(nullptr)
|
||||
, mScopeInfo(nullptr)
|
||||
, mCppcheckAttributes(nullptr)
|
||||
, mCpp11init(Cpp11init::UNKNOWN)
|
||||
, mBits(0)
|
||||
{}
|
||||
|
||||
~TokenImpl();
|
||||
|
@ -607,11 +607,13 @@ public:
|
|||
unsigned char bits() const {
|
||||
return mImpl->mBits;
|
||||
}
|
||||
std::set<TemplateSimplifier::TokenAndName*> &templateSimplifierPointers() const {
|
||||
std::set<TemplateSimplifier::TokenAndName*>* templateSimplifierPointers() const {
|
||||
return mImpl->mTemplateSimplifierPointers;
|
||||
}
|
||||
void templateSimplifierPointer(TemplateSimplifier::TokenAndName* tokenAndName) {
|
||||
mImpl->mTemplateSimplifierPointers.insert(tokenAndName);
|
||||
if (!mImpl->mTemplateSimplifierPointers)
|
||||
mImpl->mTemplateSimplifierPointers = new std::set<TemplateSimplifier::TokenAndName*>;
|
||||
mImpl->mTemplateSimplifierPointers->insert(tokenAndName);
|
||||
}
|
||||
void setBits(const unsigned char b) {
|
||||
mImpl->mBits = b;
|
||||
|
|
Loading…
Reference in New Issue