[clang] [clang][bytecode] Avoid copying function call arguments (PR #218399)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 24 05:59:40 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/218399
In most cases, we dony' need the SmallVector (we only use it to reverse the arguments in the assignment operator case).
>From eba4d4b58a6344db75c005ccf3007f364aea1b34 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 24 Aug 2026 14:43:45 +0200
Subject: [PATCH] [clang][bytecode] Avoid copying function call arguments
In most cases, we dony' need the SmallVector (we only use it to reverse
the arguments in the assignment operator case).
---
clang/lib/AST/ByteCode/Compiler.cpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 87d23bf5df0c8..8e139997c2ed1 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6207,7 +6207,8 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
}
}
- SmallVector<const Expr *, 8> Args(ArrayRef(E->getArgs(), E->getNumArgs()));
+ ArrayRef<const Expr *> Args(E->getArgs(), E->getNumArgs());
+ const Expr *ReversedArgs[2];
bool IsAssignmentOperatorCall = false;
bool ActivateLHS = false;
@@ -6220,7 +6221,9 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
const CXXRecordDecl *LHSRecord = Args[0]->getType()->getAsCXXRecordDecl();
ActivateLHS = LHSRecord && LHSRecord->hasTrivialDefaultConstructor();
IsAssignmentOperatorCall = true;
- std::reverse(Args.begin(), Args.end());
+ ReversedArgs[0] = Args[1];
+ ReversedArgs[1] = Args[0];
+ Args = ReversedArgs;
}
// Calling a static operator will still
// pass the instance, but we don't need it.
@@ -6231,7 +6234,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
if (!this->discard(E->getArg(0)))
return false;
// Drop first arg.
- Args.erase(Args.begin());
+ Args = Args.drop_front();
}
}
More information about the cfe-commits
mailing list