-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[llvm][mustache] Remove out parameters from processTags() #159190
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
Conversation
@llvm/pr-subscribers-llvm-support Author: Paul Kirth (ilovepi) ChangesFull diff: https://github.com/llvm/llvm-project/pull/159190.diff 1 Files Affected:
diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index e2de7645e8dfb..f948344883452 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -11,6 +11,7 @@
#include "llvm/Support/raw_ostream.h"
#include <cctype>
+#include <optional>
#include <sstream>
#define DEBUG_TYPE "mustache"
@@ -325,9 +326,8 @@ struct Tag {
size_t StartPosition = StringRef::npos;
};
-static Tag findNextTag(StringRef Template, size_t StartPos,
- const SmallString<8> &Open,
- const SmallString<8> &Close) {
+static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open,
+ StringRef Close) {
const StringLiteral TripleOpen("{{{");
const StringLiteral TripleClose("}}}");
@@ -368,14 +368,14 @@ static Tag findNextTag(StringRef Template, size_t StartPos,
return Result;
}
-static void processTag(const Tag &T, SmallVectorImpl<Token> &Tokens,
- SmallString<8> &Open, SmallString<8> &Close) {
+static std::optional<std::pair<StringRef, StringRef>>
+processTag(const Tag &T, SmallVectorImpl<Token> &Tokens) {
LLVM_DEBUG(dbgs() << " Found tag: \"" << T.FullMatch << "\", Content: \""
<< T.Content << "\"\n");
if (T.TagKind == Tag::Kind::Triple) {
Tokens.emplace_back(T.FullMatch.str(), "&" + T.Content.str(), '&');
LLVM_DEBUG(dbgs() << " Created UnescapeVariable token.\n");
- return;
+ return std::nullopt;
}
StringRef Interpolated = T.Content;
std::string RawBody = T.FullMatch.str();
@@ -383,7 +383,7 @@ static void processTag(const Tag &T, SmallVectorImpl<Token> &Tokens,
char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front();
Tokens.emplace_back(RawBody, Interpolated.str(), Front);
LLVM_DEBUG(dbgs() << " Created tag token of type '" << Front << "'\n");
- return;
+ return std::nullopt;
}
Tokens.emplace_back(RawBody, Interpolated.str(), '=');
StringRef DelimSpec = Interpolated.trim();
@@ -392,11 +392,9 @@ static void processTag(const Tag &T, SmallVectorImpl<Token> &Tokens,
DelimSpec = DelimSpec.trim();
auto [NewOpen, NewClose] = DelimSpec.split(' ');
- Open = NewOpen;
- Close = NewClose;
-
- LLVM_DEBUG(dbgs() << " Found Set Delimiter tag. NewOpen='" << Open
- << "', NewClose='" << Close << "'\n");
+ LLVM_DEBUG(dbgs() << " Found Set Delimiter tag. NewOpen='" << NewOpen
+ << "', NewClose='" << NewClose << "'\n");
+ return std::make_pair(NewOpen, NewClose);
}
// Simple tokenizer that splits the template into tokens.
@@ -430,7 +428,9 @@ static SmallVector<Token> tokenize(StringRef Template) {
LLVM_DEBUG(dbgs() << " Created Text token: \"" << Text << "\"\n");
}
- processTag(T, Tokens, Open, Close);
+ if (auto NewDelims = processTag(T, Tokens)) {
+ std::tie(Open, Close) = *NewDelims;
+ }
// Move past the tag.
Start = T.StartPosition + T.FullMatch.size();
|
608c9bf
to
e79233d
Compare
61bcc58
to
6a7db43
Compare
e79233d
to
0b15e73
Compare
0b15e73
to
452b7c4
Compare
3d00de1
to
f18412d
Compare
452b7c4
to
ea687e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mega-nit but shouldn't this patch be called "Use StringRef return values"? The return value is what's being changed to a pair of StringRef
s, not the parameters.
Ah, I guess the commit title is stale. thanks. I can update it. |
ea687e4
to
2ddc19d
Compare
7ca57bb
to
af8b255
Compare
2ddc19d
to
bfd4244
Compare
26f0197
to
16f12ac
Compare
Just return an optional pair of StringRefs instead.
7be7b16
to
cb3731b
Compare
We can construct the return values directly and simplify the interface.
We can construct the return values directly and simplify the interface.