Skip to content

only stringify the last line in TokenList::readfile() if necessary #243

Merged
danmar merged 2 commits intocppcheck-opensource:masterfrom
firewave:lastline
Mar 8, 2022
Merged

only stringify the last line in TokenList::readfile() if necessary #243
danmar merged 2 commits intocppcheck-opensource:masterfrom
firewave:lastline

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

@firewave firewave commented Mar 4, 2022

lastLine() is only used to check for preprocessor directives. So if it isn't such there's no need to stringify it saving a lot of unnecessary std::string operations.

The intermediate increase comes from not constructing std::string objects on-the-fly for std::string::insert() and simply using the literals.

Testing with -q -Ilib/ -D__GNUC__ lib/valueflow.cpp this saves about 8% of total Ir.

Clang 13 298,836,106 -> 295,950,055 -> 267,545,621
GCC 11 305,058,160 -> 299,749,788 -> 271,347,737

@firewave
Copy link
Copy Markdown
Collaborator Author

firewave commented Mar 4, 2022

This could probably be simplified by getting rid of lastLine() completely and creating a matcher function instead.

@firewave firewave changed the title only call lastLine() if necessary only stringify the last line in TokenList::readfile() if necessary Mar 5, 2022
@danmar danmar merged commit 86e4f22 into cppcheck-opensource:master Mar 8, 2022
@firewave firewave deleted the lastline branch March 9, 2022 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants