[llvm] ef5ba2e - [NFC] Reserve the number of operands before push_back (#106234)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 09:10:17 PDT 2024
Author: Nabeel Omer
Date: 2024-08-27T17:10:14+01:00
New Revision: ef5ba2ede79f759ff8eaad222dca36aa5f1871c3
URL: https://github.com/llvm/llvm-project/commit/ef5ba2ede79f759ff8eaad222dca36aa5f1871c3
DIFF: https://github.com/llvm/llvm-project/commit/ef5ba2ede79f759ff8eaad222dca36aa5f1871c3.diff
LOG: [NFC] Reserve the number of operands before push_back (#106234)
This reduces the number of allocations inside the loop.
Partially addresses #105836
Added:
Modified:
llvm/lib/IR/ConstantsContext.h
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantsContext.h b/llvm/lib/IR/ConstantsContext.h
index 2d12723a2329df..acf05379e8a2a6 100644
--- a/llvm/lib/IR/ConstantsContext.h
+++ b/llvm/lib/IR/ConstantsContext.h
@@ -292,6 +292,7 @@ template <class ConstantClass> struct ConstantAggrKeyType {
ConstantAggrKeyType(const ConstantClass *C,
SmallVectorImpl<Constant *> &Storage) {
assert(Storage.empty() && "Expected empty storage");
+ Storage.reserve(C->getNumOperands());
for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
Storage.push_back(C->getOperand(I));
Operands = Storage;
More information about the llvm-commits
mailing list