From: Benjamin Kramer Date: Fri, 18 Apr 2014 16:36:15 +0000 (+0000) Subject: Make the copy member of StringRef/ArrayRef generic wrt allocators. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=98b539ae65afeda465ea14da246da4c03edbb9ca;p=oota-llvm.git Make the copy member of StringRef/ArrayRef generic wrt allocators. Doesn't make sense to restrict this to BumpPtrAllocator. While there replace an explicit loop with std::equal. Some standard libraries know how to compile this down to a ::memcmp call if possible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206615 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/ArrayRef.h b/include/llvm/ADT/ArrayRef.h index be7cb51b60f..1b64fee9a59 100644 --- a/include/llvm/ADT/ArrayRef.h +++ b/include/llvm/ADT/ArrayRef.h @@ -12,7 +12,6 @@ #include "llvm/ADT/None.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/Support/Allocator.h" #include namespace llvm { @@ -121,9 +120,9 @@ namespace llvm { return Data[Length-1]; } - // copy - Allocate copy in BumpPtrAllocator and return ArrayRef to it. - ArrayRef copy(BumpPtrAllocator &Allocator) { - T *Buff = Allocator.Allocate(Length); + // copy - Allocate copy in Allocator and return ArrayRef to it. + template ArrayRef copy(Allocator &A) { + T *Buff = A.template Allocate(Length); std::copy(begin(), end(), Buff); return ArrayRef(Buff, Length); } @@ -132,10 +131,7 @@ namespace llvm { bool equals(ArrayRef RHS) const { if (Length != RHS.Length) return false; - for (size_type i = 0; i != Length; i++) - if (Data[i] != RHS.Data[i]) - return false; - return true; + return std::equal(begin(), end(), RHS.begin()); } /// slice(n) - Chop off the first N elements of the array. @@ -221,7 +217,7 @@ namespace llvm { /// Construct an MutableArrayRef from a C array. template - /*implicit*/ MutableArrayRef(T (&Arr)[N]) + /*implicit*/ LLVM_CONSTEXPR MutableArrayRef(T (&Arr)[N]) : ArrayRef(Arr) {} T *data() const { return const_cast(ArrayRef::data()); } diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index bd5a550b9f5..1f413e80553 100644 --- a/include/llvm/ADT/StringRef.h +++ b/include/llvm/ADT/StringRef.h @@ -10,7 +10,6 @@ #ifndef LLVM_ADT_STRINGREF_H #define LLVM_ADT_STRINGREF_H -#include "llvm/Support/Allocator.h" #include #include #include @@ -124,9 +123,9 @@ namespace llvm { return Data[Length-1]; } - // copy - Allocate copy in BumpPtrAllocator and return StringRef to it. - StringRef copy(BumpPtrAllocator &Allocator) { - char *S = Allocator.Allocate(Length); + // copy - Allocate copy in Allocator and return StringRef to it. + template StringRef copy(Allocator &A) { + char *S = A.template Allocate(Length); std::copy(begin(), end(), S); return StringRef(S, Length); } diff --git a/include/llvm/CodeGen/MachineValueType.h b/include/llvm/CodeGen/MachineValueType.h index 84053cac771..ad215ec0984 100644 --- a/include/llvm/CodeGen/MachineValueType.h +++ b/include/llvm/CodeGen/MachineValueType.h @@ -16,6 +16,7 @@ #define LLVM_CODEGEN_MACHINEVALUETYPE_H #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MathExtras.h" namespace llvm {