Skip to content

Commit 46d6623

Browse files
committed
Refactorization: Improved performance of Tokenizer::isFunctionParameterPassedByValue()
- Skip it for C code - Improved performance by around 80% on C++ code (3,5% of entire runtime)
1 parent 70767a3 commit 46d6623

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

lib/preprocessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,8 +1820,8 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string
18201820
continue;
18211821
const std::string::size_type behindUndefPos = undefMatchPos + (*it).size();
18221822
if ((line.size() == behindUndefPos) ||
1823-
(line[behindUndefPos] == ' ') ||
1824-
(line[behindUndefPos] == '(')) {
1823+
(line[behindUndefPos] == ' ') ||
1824+
(line[behindUndefPos] == '(')) {
18251825
match = false;
18261826
break;
18271827
}

lib/tokenize.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7974,13 +7974,16 @@ bool Tokenizer::IsScopeNoReturn(const Token *endScopeToken, bool *unknown) const
79747974

79757975
bool Tokenizer::isFunctionParameterPassedByValue(const Token *fpar) const
79767976
{
7977+
if (isC()) // C does not support references
7978+
return true;
7979+
79777980
// TODO: If symbol database is available, use it.
79787981
const Token *ftok;
79797982

79807983
// Look at function call, what parameter number is it?
79817984
unsigned int parentheses = 1;
79827985
unsigned int parameter = 1;
7983-
for (ftok = fpar; ftok; ftok = ftok->previous()) {
7986+
for (ftok = fpar->previous(); ftok; ftok = ftok->previous()) {
79847987
if (ftok->str() == "(") {
79857988
--parentheses;
79867989
if (parentheses == 0) {
@@ -8003,13 +8006,10 @@ bool Tokenizer::isFunctionParameterPassedByValue(const Token *fpar) const
80038006
return true;
80048007

80058008
// Locate function declaration..
8006-
unsigned int indentlevel = 0;
80078009
for (const Token *tok = tokens(); tok; tok = tok->next()) {
80088010
if (tok->str() == "{")
8009-
++indentlevel;
8010-
else if (tok->str() == "}")
8011-
indentlevel = (indentlevel > 0) ? indentlevel - 1U : 0U;
8012-
else if (indentlevel == 0 && Token::Match(tok, "%type% (") && tok->str() == functionName) {
8011+
tok = tok->link();
8012+
else if (Token::Match(tok, "%type% (") && tok->str() == functionName) {
80138013
// Goto parameter
80148014
tok = tok->tokAt(2);
80158015
unsigned int par = 1;

0 commit comments

Comments
 (0)