Skip to content

Commit 0a0cce4

Browse files
firewavedanmar
authored andcommitted
a few optimizations (cppcheck-opensource#162)
* optimized simplecpp::TokenList::lastLine() reduces Ir from 2722 to 1296 according to callgrind * optimized simplecpp::Token::flags() reduces Ir from 198 to 43 according to callgrind
1 parent ec4c5e2 commit 0a0cce4

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

simplecpp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,9 +1117,9 @@ std::string simplecpp::TokenList::lastLine(int maxsize) const
11171117
if (tok->comment)
11181118
continue;
11191119
if (!ret.empty())
1120-
ret = ' ' + ret;
1121-
ret = (tok->str()[0] == '\"' ? std::string("%str%")
1122-
: tok->number ? std::string("%num%") : tok->str()) + ret;
1120+
ret.insert(0, 1, ' ');
1121+
ret.insert(0, tok->str()[0] == '\"' ? std::string("%str%")
1122+
: tok->number ? std::string("%num%") : tok->str());
11231123
if (++count > maxsize)
11241124
return "";
11251125
}

simplecpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace simplecpp {
108108

109109
void flags() {
110110
name = (std::isalpha((unsigned char)string[0]) || string[0] == '_' || string[0] == '$');
111-
comment = (string.compare(0, 2, "//") == 0 || string.compare(0, 2, "/*") == 0);
111+
comment = string.size() > 1U && string[0] == '/' && (string[1] == '/' || string[1] == '*');
112112
number = std::isdigit((unsigned char)string[0]) || (string.size() > 1U && string[0] == '-' && std::isdigit((unsigned char)string[1]));
113113
op = (string.size() == 1U) ? string[0] : '\0';
114114
}

0 commit comments

Comments
 (0)