From 6cd780ff2143656df213359b7a6df9a5a9237e17 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 17 Feb 2015 15:29:18 +0000 Subject: Prefer SmallVector::append/insert over push_back loops. Same functionality, but hoists the vector growth out of the loop. llvm-svn: 229500 --- llvm/lib/IR/DebugInfo.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'llvm/lib/IR/DebugInfo.cpp') diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index deeaae7d5de..76b21d8d09d 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -344,9 +344,7 @@ void DIDescriptor::replaceAllUsesWith(LLVMContext &VMContext, DIDescriptor D) { // itself. const MDNode *DN = D; if (DbgNode == DN) { - SmallVector Ops(DbgNode->getNumOperands()); - for (size_t i = 0; i != Ops.size(); ++i) - Ops[i] = DbgNode->getOperand(i); + SmallVector Ops(DbgNode->op_begin(), DbgNode->op_end()); DN = MDNode::get(VMContext, Ops); } @@ -884,9 +882,8 @@ DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope, return cleanseInlinedVariable(DV, VMContext); // Insert inlined scope. - SmallVector Elts; - for (unsigned I = 0, E = DIVariableInlinedAtIndex; I != E; ++I) - Elts.push_back(DV->getOperand(I)); + SmallVector Elts(DV->op_begin(), + DV->op_begin() + DIVariableInlinedAtIndex); Elts.push_back(InlinedScope); DIVariable Inlined(MDNode::get(VMContext, Elts)); @@ -900,9 +897,8 @@ DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) { return DIVariable(DV); // Remove inlined scope. - SmallVector Elts; - for (unsigned I = 0, E = DIVariableInlinedAtIndex; I != E; ++I) - Elts.push_back(DV->getOperand(I)); + SmallVector Elts(DV->op_begin(), + DV->op_begin() + DIVariableInlinedAtIndex); DIVariable Cleansed(MDNode::get(VMContext, Elts)); assert(Cleansed.Verify() && "Expected to create a DIVariable"); -- cgit v1.2.3