tor-browser

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

commit cf779e134b734420732099f0c0953365a6c5eee5
parent d2c64cf7da4818155aabf5fca53c686bda14ff69
Author: serge-sans-paille <sguelton@mozilla.com>
Date:   Wed, 22 Oct 2025 08:41:36 +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 | 22+++++++++++++---------
3 files changed, 13 insertions(+), 11 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 { @@ -43,13 +45,15 @@ 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 +155,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)); }