From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- dom/canvas/DmdStdContainers.h | 100 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 dom/canvas/DmdStdContainers.h (limited to 'dom/canvas/DmdStdContainers.h') diff --git a/dom/canvas/DmdStdContainers.h b/dom/canvas/DmdStdContainers.h new file mode 100644 index 0000000000..2975abc580 --- /dev/null +++ b/dom/canvas/DmdStdContainers.h @@ -0,0 +1,100 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef dom_canvas_DmdStdContainers_h +#define dom_canvas_DmdStdContainers_h + +#include "mozilla/MemoryReporting.h" +#include "mozilla/layers/BuildConstants.h" +#include +#include + +namespace mozilla::webgl { + +// - + +template +class dmd_allocator { + public: + using value_type = T; + + private: + size_t mMallocSize = 0; + + public: + dmd_allocator() = default; + + // - + + template + friend class dmd_allocator; + + template + explicit dmd_allocator(const dmd_allocator& rhs) { + if constexpr (kIsDmd) { + mMallocSize = rhs.mMallocSize; + } + } + + // - + + value_type* allocate(const size_t n) { + const auto p = std::allocator{}.allocate(n); + if constexpr (kIsDmd) { + mMallocSize += moz_malloc_size_of(p); + } + return p; + } + + void deallocate(value_type* const p, const size_t n) { + if constexpr (kIsDmd) { + mMallocSize -= moz_malloc_size_of(p); + } + std::allocator{}.deallocate(p, n); + } + + // - + + size_t SizeOfExcludingThis(mozilla::MallocSizeOf) const { + return mMallocSize; + } +}; + +// - + +template , + class KeyEqual = std::equal_to, + class Allocator = dmd_allocator>, + class _StdT = std::unordered_map> +class dmd_unordered_map : public _StdT { + public: + using StdT = _StdT; + + size_t SizeOfExcludingThis(mozilla::MallocSizeOf mso) const { + const auto& a = StdT::get_allocator(); + return a.SizeOfExcludingThis(mso); + } +}; + +// - + +template , + class KeyEqual = std::equal_to, + class Allocator = dmd_allocator, + class _StdT = std::unordered_set> +class dmd_unordered_set : public _StdT { + public: + using StdT = _StdT; + + size_t SizeOfExcludingThis(mozilla::MallocSizeOf mso) const { + const auto& a = StdT::get_allocator(); + return a.SizeOfExcludingThis(mso); + } +}; + +// - + +} // namespace mozilla::webgl + +#endif // dom_canvas_DmdStdContainers_h -- cgit v1.2.3