[PATCH] D138378: [clang-format][NFC] Skip unneeded calculations
Björn Schäpers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 1 01:20:20 PST 2022
HazardyKnusperkeks updated this revision to Diff 479189.
HazardyKnusperkeks added a comment.
Reverted the changes in the switch. We now only have a fast path.
On my machine 4 consecutive runs of the clang format unittests, the last three times (as reported by gtest) are:
| | Before patch | After Patch |
| Run 1 | 12769ms | 12535ms |
| Run 2 | 13703ms | 12456ms |
| Run 3 | 13305ms | 12470ms |
| Avg | 13259ms | 12487ms |
|
That would be 6% speedup, more than I'd excpected.
Release Build 32 Bit Windows.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138378/new/
https://reviews.llvm.org/D138378
Files:
clang/lib/Format/WhitespaceManager.cpp
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -1430,10 +1430,14 @@
}
// FIXME: This assert should hold if we computed the column correctly.
// assert((int)C.StartOfTokenColumn >= C.Spaces);
- appendIndentText(
- ReplacementText, C.Tok->IndentLevel, std::max(0, C.Spaces),
- std::max((int)C.StartOfTokenColumn, C.Spaces) - std::max(0, C.Spaces),
- C.IsAligned);
+ unsigned Spaces = std::max(0, C.Spaces);
+ if (Style.UseTab == FormatStyle::UT_Never) {
+ ReplacementText.append(Spaces, ' ');
+ } else {
+ appendIndentText(ReplacementText, C.Tok->IndentLevel, Spaces,
+ std::max((int)C.StartOfTokenColumn, C.Spaces) - Spaces,
+ C.IsAligned);
+ }
ReplacementText.append(C.CurrentLinePrefix);
storeReplacement(C.OriginalWhitespaceRange, ReplacementText);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138378.479189.patch
Type: text/x-patch
Size: 1063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221201/386345c5/attachment.bin>
More information about the cfe-commits
mailing list