zone-utils.h 868 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_ZONE_ZONE_UTILS_H_
#define V8_ZONE_ZONE_UTILS_H_

#include <algorithm>
#include <type_traits>

11
#include "src/base/vector.h"
12 13 14 15 16 17
#include "src/zone/zone.h"

namespace v8 {
namespace internal {

template <typename T>
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 25 26 27
    MemCopy(data, other.data(), length * sizeof(T));
  } else {
    std::copy(other.begin(), other.end(), data);
  }
28
  return base::Vector<T>(data, length);
29 30 31 32 33 34
}

}  // namespace internal
}  // namespace v8

#endif  // V8_ZONE_ZONE_UTILS_H_