Skip to content

optimized std::stack usage in simplecpp::TokenList::combineOperators()#659

Open
firewave wants to merge 2 commits into
cppcheck-opensource:masterfrom
firewave:combine
Open

optimized std::stack usage in simplecpp::TokenList::combineOperators()#659
firewave wants to merge 2 commits into
cppcheck-opensource:masterfrom
firewave:combine

Conversation

@firewave

@firewave firewave commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator
  • use std::vector as underlying container for std::stack
  • initialize std::stack with initial value instead of inserting it

@firewave

firewave commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

This cuts the Ir for the function in question in half.

Running ./testrunner in valgrind:

GCC 16 - 73,545,066 -> 73,089,626 -> 72,638,322
Clang 22 - 71,260,479 -> 70,736,809 -> 70,321,207

Comment thread simplecpp.cpp
{
std::stack<bool> executableScope;
executableScope.push(false);
std::stack<bool, std::vector<bool>> executableScope{{false}};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't std::vector<bool> bad to use overall in c++11..
are you sure that all usage here will work fine..

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is about performance and valgrind indicates that is fine in either compiler so I see no problem.

libc++ has been adding special handling for vector<bool> and we are also not using it as a bit field here (which is the common usage for that IIRC).

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