-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang-format] Fixed bad performance with enabled qualifier fixer.
This fixes github issue #57117: If the "QualifierAlignment" option of clang-format is set to anything else but "Leave", the "QualifierAlignmentFixer" pass gets enabled. This pass scales quadratically with the number of preprocessor branches, i.e. with the number of elements in TokenAnalyzer::UnwrappedLines. The reason is that QualifierAlignmentFixer::process() generates the UnwrappedLines, but then QualifierAlignmentFixer::analyze() calls LeftRightQualifierAlignmentFixer::process() several times (once for each qualifier) which again each time generates the UnwrappedLines. This commit gets rid of this double loop by registering the individual LeftRightQualifierAlignmentFixer passes directly in the top most container of passes (local variable "Passes" in reformat()). With this change, the original example in the github issue #57117 now takes only around 3s instead of >300s to format. Since QualifierAlignmentFixer::analyze() got deleted, we also no longer have the code with the NonNoOpFixes. This causes replacements that end up not changing anything to appear in the list of final replacements. There is a unit test to check that this does not happen: QualifierFixerTest.NoOpQualifierReplacements. However, it got broken at some point in time. So this commit fixes the test. To keep the behavior that no no-op replacements should appear from the qualifier fixer, the corresponding code from QualifierAlignmentFixer::analyze() was moved to the top reformat() function. Thus, is now done for **every** replacement of every formatting pass. If no-op replacements are a problem for the qualifier fixer, then it seems to be a good idea to filter them out always. See #57117 (comment) for some more details. Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D153228
- Loading branch information
1 parent
cf244b5
commit 899c867
Showing
4 changed files
with
39 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters