Skip to content

Add caching of conditional directive chains #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2025

Conversation

glankk
Copy link
Contributor

@glankk glankk commented Jul 7, 2025

Adds caching for elif, else, and endif tokens that follow if, elif, and else the first time they're processed, so that the preprocessor can jump directly to them the next time the conditional block should be skipped.

The next conditional token is cached in the previous token's mutable const Token *nextcond. Having a public mutable member is a bit awkward but seemed like the best solution. The alternative would be to make nextcond private and make preprocess a friend, or make preprocess take a non-const TokenList.

In the test case that I used for #447 this change brings the runtime down from over 12 minutes to less than one minute.

@danmar danmar merged commit f566848 into danmar:master Jul 7, 2025
16 checks passed
@glankk glankk deleted the skip_conditional branch July 7, 2025 08:38
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