From d0e99606a405720d9900e2ea853c9b21b9d63552 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 5 Dec 2015 07:41:42 +0000 Subject: [PATCH] Use std::copy and std::transform instead of manual loops. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254845 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Stmt.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index a060be1137..10434463b8 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -731,30 +731,29 @@ void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr, assert(NumAsmToks == asmtoks.size()); assert(NumClobbers == clobbers.size()); - unsigned NumExprs = exprs.size(); - assert(NumExprs == NumOutputs + NumInputs); - assert(NumExprs == constraints.size()); + assert(exprs.size() == NumOutputs + NumInputs); + assert(exprs.size() == constraints.size()); AsmStr = copyIntoContext(C, asmstr); - Exprs = new (C) Stmt*[NumExprs]; - for (unsigned i = 0, e = NumExprs; i != e; ++i) - Exprs[i] = exprs[i]; + Exprs = new (C) Stmt*[exprs.size()]; + std::copy(exprs.begin(), exprs.end(), Exprs); - AsmToks = new (C) Token[NumAsmToks]; - for (unsigned i = 0, e = NumAsmToks; i != e; ++i) - AsmToks[i] = asmtoks[i]; + AsmToks = new (C) Token[asmtoks.size()]; + std::copy(asmtoks.begin(), asmtoks.end(), AsmToks); - Constraints = new (C) StringRef[NumExprs]; - for (unsigned i = 0, e = NumExprs; i != e; ++i) { - Constraints[i] = copyIntoContext(C, constraints[i]); - } + Constraints = new (C) StringRef[exprs.size()]; + std::transform(constraints.begin(), constraints.end(), Constraints, + [&](StringRef Constraint) { + return copyIntoContext(C, Constraint); + }); Clobbers = new (C) StringRef[NumClobbers]; - for (unsigned i = 0, e = NumClobbers; i != e; ++i) { - // FIXME: Avoid the allocation/copy if at all possible. - Clobbers[i] = copyIntoContext(C, clobbers[i]); - } + // FIXME: Avoid the allocation/copy if at all possible. + std::transform(clobbers.begin(), clobbers.end(), Clobbers, + [&](StringRef Clobber) { + return copyIntoContext(C, Clobber); + }); } IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, -- 2.40.0