Skip to content

Commit 961d32d

Browse files
committed
[Parser] Pass token to TokenReceiver by reference
Small peformance improvement: Token is larger than a pointer and not modified in the performance-criticial TokenReceivers, so we can pass it by reference.
1 parent 00d09f7 commit 961d32d

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

include/swift/Parse/Parser.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace swift {
8787
class ConsumeTokenReceiver {
8888
public:
8989
/// This is called when a token is consumed.
90-
virtual void receive(Token Tok) {}
90+
virtual void receive(const Token &Tok) {}
9191

9292
/// This is called to update the kind of a token whose start location is Loc.
9393
virtual void registerTokenKindChange(SourceLoc Loc, tok NewKind) {};
@@ -488,9 +488,7 @@ class Parser {
488488
std::vector<Token> delayedTokens;
489489
DelayedTokenReceiver(ConsumeTokenReceiver *&receiver):
490490
savedConsumer(receiver, this) {}
491-
void receive(Token tok) override {
492-
delayedTokens.push_back(tok);
493-
}
491+
void receive(const Token &tok) override { delayedTokens.push_back(tok); }
494492
Optional<std::vector<Token>> finalize() override {
495493
llvm_unreachable("Cannot finalize a DelayedTokenReciever");
496494
}

lib/Parse/Parser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ class TokenRecorder: public ConsumeTokenReceiver {
476476
TokenKindChangeMap[Loc.getOpaquePointerValue()] = NewKind;
477477
}
478478

479-
void receive(Token Tok) override {
479+
void receive(const Token &TokParam) override {
480+
Token Tok = TokParam;
480481
// We filter out all tokens without valid location
481482
if(Tok.getLoc().isInvalid())
482483
return;

0 commit comments

Comments
 (0)