tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 60ddde8182fef6c697f9f40d3b76136b6653cc96
parent b8408dc34521217a11cd262f962df38acd49ffa1
Author: serge-sans-paille <sguelton@mozilla.com>
Date:   Tue, 21 Oct 2025 15:44:59 +0000

Bug 1993199 - Adjust implementation of mozilla::PodZero r=emilio

As a side effect, also remove unused inclusion of mfbt/PodOperations.h

Differential Revision: https://phabricator.services.mozilla.com/D267933

Diffstat:
Mdom/base/nsWindowMemoryReporter.h | 1-
Mdom/base/nsWindowSizes.h | 1-
Mmfbt/PodOperations.h | 27+++++++++++++++------------
3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/dom/base/nsWindowMemoryReporter.h b/dom/base/nsWindowMemoryReporter.h @@ -7,7 +7,6 @@ #ifndef nsWindowMemoryReporter_h__ #define nsWindowMemoryReporter_h__ -#include "mozilla/PodOperations.h" #include "mozilla/TimeStamp.h" #include "nsIMemoryReporter.h" #include "nsIObserver.h" diff --git a/dom/base/nsWindowSizes.h b/dom/base/nsWindowSizes.h @@ -8,7 +8,6 @@ #define nsWindowSizes_h #include "mozilla/Assertions.h" -#include "mozilla/PodOperations.h" #include "mozilla/SizeOfState.h" #include "nsStyleStructList.h" diff --git a/mfbt/PodOperations.h b/mfbt/PodOperations.h @@ -18,8 +18,10 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" -#include <stdint.h> -#include <string.h> +#include <cstdint> +#include <cstring> +#include <limits> +#include <type_traits> namespace mozilla { @@ -39,17 +41,18 @@ static MOZ_ALWAYS_INLINE void PodZero(T* aT) { /** Set the contents of |aNElem| elements starting at |aT| to 0. */ template <typename T> -static MOZ_ALWAYS_INLINE void PodZero(T* aT, size_t aNElem) { - static_assert(std::is_trivially_copyable_v<T>, - "PodZero requires trivially copyable types"); +static MOZ_ALWAYS_INLINE void PodZero(T* aT, size_t aNElem) { static_assert(std::is_trivially_copyable_v<T>, "PodZero requires + trivially copyable types"); /* - * This function is often called with 'aNElem' small; we use an inline loop - * instead of calling 'memset' with a non-constant length. The compiler - * should inline the memset call with constant size, though. + * NB: If the caller uses a constant size, both GCC and Clang inline the + * memset call if they find it profitable. + * + * If the value is dynamic, some might think that it's more profitable to + * perform an explicit loop over the aNElem. It turns out Clang rolls back the + * loop anyway, so even if GCC doesn't, keep the codebase simple and clearly + * convey the intent instead of trying to outsmart the compiler. */ - for (T* end = aT + aNElem; aT < end; aT++) { - memset(aT, 0, sizeof(T)); - } + memset(aT, 0, sizeof(T) * aNElem); } /** Set the contents of |aNElem| elements starting at |aT| to 0. */ @@ -151,7 +154,7 @@ template <typename T> static MOZ_ALWAYS_INLINE void PodMove(T* aDst, const T* aSrc, size_t aNElem) { static_assert(std::is_trivially_copyable_v<T>, "PodMove requires trivially copyable types"); - MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T), + MOZ_ASSERT(aNElem <= std::numeric_limits<size_t>::max() / sizeof(T), "trying to move an impossible number of elements"); memmove(aDst, aSrc, aNElem * sizeof(T)); }