• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_ZONE_ZONE_UTILS_H_
6 #define V8_ZONE_ZONE_UTILS_H_
7 
8 #include <algorithm>
9 #include <type_traits>
10 
11 #include "src/base/vector.h"
12 #include "src/zone/zone.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 template <typename T>
CloneVector(Zone * zone,const base::Vector<const T> & other)18 base::Vector<T> CloneVector(Zone* zone, const base::Vector<const T>& other) {
19   int length = other.length();
20   if (length == 0) return base::Vector<T>();
21 
22   T* data = zone->NewArray<T>(length);
23   if (std::is_trivially_copyable<T>::value) {
24     MemCopy(data, other.data(), length * sizeof(T));
25   } else {
26     std::copy(other.begin(), other.end(), data);
27   }
28   return base::Vector<T>(data, length);
29 }
30 
31 }  // namespace internal
32 }  // namespace v8
33 
34 #endif  // V8_ZONE_ZONE_UTILS_H_
35