Skip to content

Commit 4da4a12

Browse files
committed
optimized TokenList::readfile() a bit
1 parent 3082bd7 commit 4da4a12

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

simplecpp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static bool startsWith(const std::string &str, const std::string &s)
138138

139139
static bool endsWith(const std::string &s, const std::string &e)
140140
{
141-
return (s.size() >= e.size() && s.compare(s.size() - e.size(), e.size(), e) == 0);
141+
return std::equal(e.rbegin(), e.rend(), s.rbegin());
142142
}
143143

144144
static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
@@ -568,7 +568,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
568568

569569
TokenString currentToken;
570570

571-
if (cback() && cback()->location.line == location.line && cback()->previous && cback()->previous->op == '#' && (lastLine() == "# error" || lastLine() == "# warning")) {
571+
if (cback() && cback()->previous && cback()->previous->op == '#' && cback()->location.line == location.line && isLastLinePreprocessor() && (lastLine() == "# error" || lastLine() == "# warning")) {
572572
char prev = ' ';
573573
while (istr.good() && (prev == '\\' || (ch != '\r' && ch != '\n'))) {
574574
currentToken += ch;
@@ -710,7 +710,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
710710
else
711711
back()->setstr(prefix + s);
712712

713-
if (newlines > 0 && lastLine().compare(0,9,"# define ") == 0) {
713+
if (newlines > 0 && isLastLinePreprocessor() && lastLine().compare(0,9,"# define ") == 0) {
714714
multiline += newlines;
715715
location.adjust(s);
716716
} else {
@@ -723,7 +723,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
723723
currentToken += ch;
724724
}
725725

726-
if (currentToken == "<" && lastLine() == "# include") {
726+
if (*currentToken.begin() == '<' && isLastLinePreprocessor() && lastLine() == "# include") {
727727
currentToken = readUntil(istr, location, '<', '>', outputList, bom);
728728
if (currentToken.size() < 2U)
729729
return;

0 commit comments

Comments
 (0)