Debian Codegraph @

js/src/wasm/WasmUtility.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef wasm_utility_h
8 #define wasm_utility_h
9
10 #include "mozilla/Maybe.h"
11
12 #include <algorithm>
13 namespace js {
14 namespace wasm {
15
16 template <class Container1, class Container2>
17 static inline bool EqualContainers(const Container1& lhs,
18 const Container2& rhs) {
19 return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
20 }
21
22 #define WASM_DECLARE_POD_VECTOR(Type, VectorName) \
23 } \
24 } \
25 static_assert(std::is_trivially_copyable<js::wasm::Type>::value, \
26 "Must be trivially copyable"); \
27 static_assert(std::is_trivially_destructible<js::wasm::Type>::value, \
28 "Must be trivially destructible"); \
29 namespace js { \
30 namespace wasm { \
31 using VectorName = Vector<Type, 0, SystemAllocPolicy>;
32
33 template <class T>
34 static inline size_t SizeOfVectorElementExcludingThis(
35 const T& elem, mozilla::MallocSizeOf mallocSizeOf) {
36 return elem.sizeOfExcludingThis(mallocSizeOf);
37 }
38
39 template <class T>
40 static inline size_t SizeOfVectorElementExcludingThis(
41 const RefPtr<T>& elem, mozilla::MallocSizeOf mallocSizeOf) {
42 return elem->sizeOfExcludingThis(mallocSizeOf);
43 }
44
45 template <class T, size_t N>
46 static inline size_t SizeOfVectorExcludingThis(
47 const mozilla::Vector<T, N, SystemAllocPolicy>& vec,
48 mozilla::MallocSizeOf mallocSizeOf) {
49 size_t size = vec.sizeOfExcludingThis(mallocSizeOf);
50 for (const T& t : vec) {
51 size += SizeOfVectorElementExcludingThis(t, mallocSizeOf);
52 }
53 return size;
54 }
55
56 template <class T>
57 static inline size_t SizeOfMaybeExcludingThis(
58 const mozilla::Maybe<T>& maybe, mozilla::MallocSizeOf mallocSizeOf) {
59 return maybe ? maybe->sizeOfExcludingThis(mallocSizeOf) : 0;
60 }
61
62 } // namespace wasm
63 } // namespace js
64
65 #endif // wasm_utility_h