Store Token::_originalName on heap, since it is only used for a small amount of Tokens (reduce memory usage of TokenList by ~12% (x64))
This commit is contained in:
parent
ec1bd420a7
commit
7ea7ee0005
|
@ -39,7 +39,6 @@ Token::Token(Token **t) :
|
||||||
_link(0),
|
_link(0),
|
||||||
_scope(0),
|
_scope(0),
|
||||||
_function(0), // Initialize whole union
|
_function(0), // Initialize whole union
|
||||||
_str(""),
|
|
||||||
_varId(0),
|
_varId(0),
|
||||||
_fileIndex(0),
|
_fileIndex(0),
|
||||||
_linenr(0),
|
_linenr(0),
|
||||||
|
@ -48,13 +47,14 @@ Token::Token(Token **t) :
|
||||||
_flags(0),
|
_flags(0),
|
||||||
_astOperand1(nullptr),
|
_astOperand1(nullptr),
|
||||||
_astOperand2(nullptr),
|
_astOperand2(nullptr),
|
||||||
_astParent(nullptr)
|
_astParent(nullptr),
|
||||||
|
_originalName(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Token::~Token()
|
Token::~Token()
|
||||||
{
|
{
|
||||||
|
delete _originalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Token::update_property_info()
|
void Token::update_property_info()
|
||||||
|
@ -174,7 +174,10 @@ void Token::deleteThis()
|
||||||
_scope = _next->_scope;
|
_scope = _next->_scope;
|
||||||
_function = _next->_function;
|
_function = _next->_function;
|
||||||
_variable = _next->_variable;
|
_variable = _next->_variable;
|
||||||
_originalName = _next->_originalName;
|
if (_next->_originalName) {
|
||||||
|
_originalName = _next->_originalName;
|
||||||
|
_next->_originalName = nullptr;
|
||||||
|
}
|
||||||
values = _next->values;
|
values = _next->values;
|
||||||
if (_link)
|
if (_link)
|
||||||
_link->link(this);
|
_link->link(this);
|
||||||
|
@ -191,7 +194,10 @@ void Token::deleteThis()
|
||||||
_scope = _previous->_scope;
|
_scope = _previous->_scope;
|
||||||
_function = _previous->_function;
|
_function = _previous->_function;
|
||||||
_variable = _previous->_variable;
|
_variable = _previous->_variable;
|
||||||
_originalName = _previous->_originalName;
|
if (_previous->_originalName) {
|
||||||
|
_originalName = _previous->_originalName;
|
||||||
|
_previous->_originalName = nullptr;
|
||||||
|
}
|
||||||
values = _previous->values;
|
values = _previous->values;
|
||||||
if (_link)
|
if (_link)
|
||||||
_link->link(this);
|
_link->link(this);
|
||||||
|
@ -931,7 +937,8 @@ void Token::insertToken(const std::string &tokenStr, const std::string &original
|
||||||
else
|
else
|
||||||
newToken = new Token(tokensBack);
|
newToken = new Token(tokensBack);
|
||||||
newToken->str(tokenStr);
|
newToken->str(tokenStr);
|
||||||
newToken->_originalName = originalNameStr;
|
if (!originalNameStr.empty())
|
||||||
|
newToken->originalName(originalNameStr);
|
||||||
newToken->_linenr = _linenr;
|
newToken->_linenr = _linenr;
|
||||||
newToken->_fileIndex = _fileIndex;
|
newToken->_fileIndex = _fileIndex;
|
||||||
newToken->_progressValue = _progressValue;
|
newToken->_progressValue = _progressValue;
|
||||||
|
|
11
lib/token.h
11
lib/token.h
|
@ -620,7 +620,7 @@ public:
|
||||||
* @return the original name.
|
* @return the original name.
|
||||||
*/
|
*/
|
||||||
const std::string & originalName() const {
|
const std::string & originalName() const {
|
||||||
return _originalName;
|
return _originalName ? *_originalName : emptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -628,7 +628,10 @@ public:
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void originalName(T&& name) {
|
void originalName(T&& name) {
|
||||||
_originalName = name;
|
if (!_originalName)
|
||||||
|
_originalName = new std::string(name);
|
||||||
|
else
|
||||||
|
*_originalName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Values of token */
|
/** Values of token */
|
||||||
|
@ -687,6 +690,7 @@ private:
|
||||||
*/
|
*/
|
||||||
static int firstWordLen(const char *str);
|
static int firstWordLen(const char *str);
|
||||||
|
|
||||||
|
std::string _str;
|
||||||
|
|
||||||
Token *_next;
|
Token *_next;
|
||||||
Token *_previous;
|
Token *_previous;
|
||||||
|
@ -699,7 +703,6 @@ private:
|
||||||
const Variable *_variable;
|
const Variable *_variable;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string _str;
|
|
||||||
unsigned int _varId;
|
unsigned int _varId;
|
||||||
unsigned int _fileIndex;
|
unsigned int _fileIndex;
|
||||||
unsigned int _linenr;
|
unsigned int _linenr;
|
||||||
|
@ -761,7 +764,7 @@ private:
|
||||||
Token *_astParent;
|
Token *_astParent;
|
||||||
|
|
||||||
// original name like size_t
|
// original name like size_t
|
||||||
std::string _originalName;
|
std::string* _originalName;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void astOperand1(Token *tok);
|
void astOperand1(Token *tok);
|
||||||
|
|
|
@ -165,7 +165,8 @@ void TokenList::addtoken(const Token * tok, const unsigned int lineno, const uns
|
||||||
_front = new Token(&_back);
|
_front = new Token(&_back);
|
||||||
_back = _front;
|
_back = _front;
|
||||||
_back->str(tok->str());
|
_back->str(tok->str());
|
||||||
_back->originalName(tok->originalName());
|
if (!tok->originalName().empty())
|
||||||
|
_back->originalName(tok->originalName());
|
||||||
}
|
}
|
||||||
|
|
||||||
_back->linenr(lineno);
|
_back->linenr(lineno);
|
||||||
|
|
Loading…
Reference in New Issue