v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
zone-utils.h
Go to the documentation of this file.
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
14namespace v8 {
15namespace internal {
16
17template <typename T>
19 int length = other.length();
20 if (length == 0) return base::Vector<T>();
21
22 T* data = zone->AllocateArray<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_
int length() const
Definition vector.h:64
T * AllocateArray(size_t length)
Definition zone.h:127
base::Vector< T > CloneVector(Zone *zone, base::Vector< const T > other)
Definition zone-utils.h:18
void MemCopy(void *dest, const void *src, size_t size)
Definition memcopy.h:124