From 89d9b81a3a7802fcf04770d8129477a8e2dd8d85 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Mon, 25 Jul 2011 10:14:44 +0000 Subject: [PATCH] Use ArrayRef in the (protected) constructors of ConstantArray, ConstantStruct and ConstantVector. llvm-svn: 135905 --- llvm/include/llvm/Constants.h | 6 +++--- llvm/lib/VMCore/Constants.cpp | 39 +++++++++++------------------------ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/llvm/include/llvm/Constants.h b/llvm/include/llvm/Constants.h index 20ed1344dbf1..e011c56956a8 100644 --- a/llvm/include/llvm/Constants.h +++ b/llvm/include/llvm/Constants.h @@ -329,7 +329,7 @@ class ConstantArray : public Constant { std::vector >; ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT protected: - ConstantArray(ArrayType *T, const std::vector &Val); + ConstantArray(ArrayType *T, ArrayRef Val); public: // ConstantArray accessors static Constant *get(ArrayType *T, ArrayRef V); @@ -400,7 +400,7 @@ class ConstantStruct : public Constant { std::vector >; ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT protected: - ConstantStruct(StructType *T, const std::vector &Val); + ConstantStruct(StructType *T, ArrayRef Val); public: // ConstantStruct accessors static Constant *get(StructType *T, ArrayRef V); @@ -461,7 +461,7 @@ class ConstantVector : public Constant { std::vector >; ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT protected: - ConstantVector(VectorType *T, const std::vector &Val); + ConstantVector(VectorType *T, ArrayRef Val); public: // ConstantVector accessors static Constant *get(ArrayRef V); diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index d7e35c021e56..9d0f7cc3c8e0 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -573,21 +573,16 @@ bool ConstantFP::isExactlyValue(const APFloat &V) const { //===----------------------------------------------------------------------===// -ConstantArray::ConstantArray(ArrayType *T, - const std::vector &V) +ConstantArray::ConstantArray(ArrayType *T, ArrayRef V) : Constant(T, ConstantArrayVal, OperandTraits::op_end(this) - V.size(), V.size()) { assert(V.size() == T->getNumElements() && "Invalid initializer vector for constant array"); - Use *OL = OperandList; - for (std::vector::const_iterator I = V.begin(), E = V.end(); - I != E; ++I, ++OL) { - Constant *C = *I; - assert(C->getType() == T->getElementType() && + for (unsigned i = 0, e = V.size(); i != e; ++i) + assert(V[i]->getType() == T->getElementType() && "Initializer for array element doesn't match array element type!"); - *OL = C; - } + std::copy(V.begin(), V.end(), op_begin()); } Constant *ConstantArray::get(ArrayType *Ty, ArrayRef V) { @@ -653,21 +648,16 @@ StructType *ConstantStruct::getTypeForElements(ArrayRef V, } -ConstantStruct::ConstantStruct(StructType *T, - const std::vector &V) +ConstantStruct::ConstantStruct(StructType *T, ArrayRef V) : Constant(T, ConstantStructVal, OperandTraits::op_end(this) - V.size(), V.size()) { assert((T->isOpaque() || V.size() == T->getNumElements()) && "Invalid initializer vector for constant structure"); - Use *OL = OperandList; - for (std::vector::const_iterator I = V.begin(), E = V.end(); - I != E; ++I, ++OL) { - Constant *C = *I; - assert((T->isOpaque() || C->getType() == T->getElementType(I-V.begin())) && + for (unsigned i = 0, e = V.size(); i != e; ++i) + assert((T->isOpaque() || V[i]->getType() == T->getElementType(i)) && "Initializer for struct element doesn't match struct element type!"); - *OL = C; - } + std::copy(V.begin(), V.end(), op_begin()); } // ConstantStruct accessors. @@ -692,19 +682,14 @@ Constant* ConstantStruct::get(StructType *T, ...) { return get(T, Values); } -ConstantVector::ConstantVector(VectorType *T, - const std::vector &V) +ConstantVector::ConstantVector(VectorType *T, ArrayRef V) : Constant(T, ConstantVectorVal, OperandTraits::op_end(this) - V.size(), V.size()) { - Use *OL = OperandList; - for (std::vector::const_iterator I = V.begin(), E = V.end(); - I != E; ++I, ++OL) { - Constant *C = *I; - assert(C->getType() == T->getElementType() && + for (size_t i = 0, e = V.size(); i != e; i++) + assert(V[i]->getType() == T->getElementType() && "Initializer for vector element doesn't match vector element type!"); - *OL = C; - } + std::copy(V.begin(), V.end(), op_begin()); } // ConstantVector accessors.