-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[llvm][mustache] Avoid extra allocations in parseSection #159199
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
Open
ilovepi
wants to merge
1
commit into
users/ilovepi/mustache-single-pass
Choose a base branch
from
users/ilovepi/mustache-parse-section-opt
base: users/ilovepi/mustache-single-pass
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[llvm][mustache] Avoid extra allocations in parseSection #159199
ilovepi
wants to merge
1
commit into
users/ilovepi/mustache-single-pass
from
users/ilovepi/mustache-parse-section-opt
Conversation
This file contains hidden or 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 was referenced Sep 16, 2025
This was referenced Sep 16, 2025
@llvm/pr-subscribers-llvm-support Author: Paul Kirth (ilovepi) ChangesWe don't need to have extra allocations when concatenating raw bodies. Full diff: https://github.com/llvm/llvm-project/pull/159199.diff 1 Files Affected:
diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 8139e9eb4717f..829643d1f35d2 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -590,9 +590,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type Ty,
size_t Start = CurrentPtr;
parseMustache(CurrentNode);
const size_t End = CurrentPtr - 1;
+
+ size_t RawBodySize = 0;
+ for (size_t I = Start; I < End; ++I)
+ RawBodySize += Tokens[I].RawBody.size();
+
SmallString<128> RawBody;
- for (std::size_t I = Start; I < End; I++)
+ RawBody.reserve(RawBodySize);
+ for (std::size_t I = Start; I < End; ++I)
RawBody += Tokens[I].RawBody;
+
CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody)));
Parent->addChild(CurrentNode);
}
|
410fdc8
to
f5b3210
Compare
ac3d77f
to
5c65ae1
Compare
f5b3210
to
2de3866
Compare
petrhosek
approved these changes
Sep 22, 2025
2de3866
to
c6e7926
Compare
05bfb24
to
f37d180
Compare
c6e7926
to
28deddc
Compare
f37d180
to
f93d738
Compare
ca0de5e
to
919e389
Compare
f93d738
to
2a7ebd4
Compare
919e389
to
943c634
Compare
057142b
to
92378de
Compare
0cd6777
to
d5cdf06
Compare
baee147
to
f048f53
Compare
d5cdf06
to
66ea253
Compare
f048f53
to
a81f574
Compare
66ea253
to
520cdc1
Compare
a81f574
to
228b984
Compare
37926e7
to
7adaaa3
Compare
228b984
to
3456d1b
Compare
7adaaa3
to
9afa122
Compare
3456d1b
to
7909f20
Compare
We don't need to have extra allocations when concatenating raw bodies.
7909f20
to
f276893
Compare
9afa122
to
7d30130
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We don't need to have extra allocations when concatenating raw bodies.