SmallMap, FlatArrayMap::copyFrom
authorStepan Dyatkovskiy <stpworld@narod.ru>
Thu, 14 Jun 2012 16:59:43 +0000 (16:59 +0000)
committerStepan Dyatkovskiy <stpworld@narod.ru>
Thu, 14 Jun 2012 16:59:43 +0000 (16:59 +0000)
Replaced memcpy with std::copy, since the first one may work improperly with non POD data.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158457 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/FlatArrayMap.h

index b414cde7a163a58131b4dd0ebe5b109ddce0df3d..2d60ef88373c475fa5da18514fc10a0c25a8b53b 100644 (file)
@@ -96,11 +96,13 @@ namespace llvm {
 
 
   void copyFrom(const self &RHS) {
-    memcpy(Array, RHS.Array, sizeof(value_type) * (MaxArraySize + 1));
+    std::copy(RHS.Array, RHS.Array + MaxArraySize + 1, Array);
     NumElements = RHS.NumElements;
   }
 
   void init () {
+    // Even if Array contains non POD, use memset for last element,
+    // since it is used as end() iterator only.
     memset(Array + MaxArraySize, 0, sizeof(value_type));
     NumElements = 0;
   }