Skip to content

[NFC] Reserve the number of operands before push_back #106234

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

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

omern1
Copy link
Member

@omern1 omern1 commented Aug 27, 2024

This reduces the number of allocations inside the loop.

Partially addresses #105836

@omern1 omern1 requested a review from nikic August 27, 2024 14:56
@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2024

@llvm/pr-subscribers-llvm-ir

Author: Nabeel Omer (omern1)

Changes

Partially addresses #105836


Full diff: https://github.com/llvm/llvm-project/pull/106234.diff

1 Files Affected:

  • (modified) llvm/lib/IR/ConstantsContext.h (+1)
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;

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@omern1 omern1 merged commit ef5ba2e into llvm:main Aug 27, 2024
8 of 10 checks passed
@omern1 omern1 deleted the add_reserve branch August 27, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants