commit b9ab86d50825ad1e98c2f6a24e8c89864cb1d36a
parent 21fb33016fbfc2daa694ccc2beccb50058073213
Author: serge-sans-paille <sguelton@mozilla.com>
Date: Thu, 6 Nov 2025 15:25:15 +0000
Bug 1998400 - Make empty global variables of type nsTArray MOZ_CONSTINIT instead of MOZ_RUNINIT r=emilio,geckoview-reviewers,media-playback-reviewers,places-reviewers,ohall,chunmin
Differential Revision: https://phabricator.services.mozilla.com/D271390
Diffstat:
9 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/dom/base/PlacesObservers.cpp b/dom/base/PlacesObservers.cpp
@@ -67,7 +67,7 @@ using WeakNativeListeners =
// Even if NotifyListeners is called any timing, we mange the notifications with
// adding to this queue, then sending in sequence. This avoids sending nested
// notifications while previous ones are still being sent.
-MOZ_RUNINIT static nsTArray<Sequence<OwningNonNull<PlacesEvent>>>
+MOZ_CONSTINIT static nsTArray<Sequence<OwningNonNull<PlacesEvent>>>
gNotificationQueue;
uint32_t GetEventTypeFlag(PlacesEventType aEventType) {
diff --git a/dom/media/eme/MediaKeySystemAccess.cpp b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -45,7 +45,7 @@ namespace mozilla::dom {
#ifdef MOZ_WMF_CDM
# include "nsIWindowsMediaFoundationCDMOriginsListService.h"
-MOZ_RUNINIT static nsTArray<IPCOriginStatusEntry> sOriginStatusEntries;
+MOZ_CONSTINIT static nsTArray<IPCOriginStatusEntry> sOriginStatusEntries;
#endif
#define LOG(msg, ...) \
diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
@@ -123,7 +123,7 @@ typedef mozilla::layers::BufferRecycleBin BufferRecycleBin;
namespace mozilla {
#if defined(MOZ_USE_HWDECODE) && defined(MOZ_WIDGET_GTK)
-MOZ_RUNINIT nsTArray<AVCodecID>
+MOZ_CONSTINIT nsTArray<AVCodecID>
FFmpegVideoDecoder<LIBAV_VER>::mAcceleratedFormats;
#endif
diff --git a/dom/workers/ScriptLoader.h b/dom/workers/ScriptLoader.h
@@ -13,6 +13,7 @@
#include "mozilla/Maybe.h"
#include "mozilla/dom/WorkerBinding.h"
#include "mozilla/dom/WorkerCommon.h"
+#include "mozilla/dom/WorkerLoadContext.h"
#include "mozilla/dom/WorkerRef.h"
#include "mozilla/dom/workerinternals/WorkerModuleLoader.h"
#include "nsIContentPolicy.h"
@@ -34,7 +35,6 @@ namespace dom {
class ClientInfo;
class Document;
-class ThreadSafeRequestHandle;
struct WorkerLoadInfo;
class WorkerPrivate;
class SerializedStackHolder;
diff --git a/toolkit/xre/nsX11ErrorHandler.cpp b/toolkit/xre/nsX11ErrorHandler.cpp
@@ -24,7 +24,7 @@ struct XExtension {
XExtension(const char* aName, int aCode) : name(aName), major_opcode(aCode) {}
};
-MOZ_RUNINIT static nsTArray<XExtension> sXExtensions;
+MOZ_CONSTINIT static nsTArray<XExtension> sXExtensions;
// man XSetErrorHandler says "the error handler should not call any
// functions (directly or indirectly) on the display that will generate
diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp
@@ -129,7 +129,7 @@ static mozilla::LazyLogModule sGVSupportLog("GeckoViewSupport");
// All the toplevel windows that have been created; these are in
// stacking order, so the window at gTopLevelWindows[0] is the topmost
// one.
-MOZ_RUNINIT static nsTArray<nsWindow*> gTopLevelWindows;
+MOZ_CONSTINIT static nsTArray<nsWindow*> gTopLevelWindows;
static const double kTouchResampleVsyncAdjustMs = 5.0;
diff --git a/widget/gtk/WaylandVsyncSource.cpp b/widget/gtk/WaylandVsyncSource.cpp
@@ -41,7 +41,7 @@ static float GetFPS(TimeDuration aVsyncRate) {
return 1000.0f / float(aVsyncRate.ToMilliseconds());
}
-MOZ_RUNINIT static nsTArray<WaylandVsyncSource*> gWaylandVsyncSources;
+MOZ_CONSTINIT static nsTArray<WaylandVsyncSource*> gWaylandVsyncSources;
Maybe<TimeDuration> WaylandVsyncSource::GetFastestVsyncRate() {
Maybe<TimeDuration> retVal;
diff --git a/xpcom/ds/nsTArray.h b/xpcom/ds/nsTArray.h
@@ -509,7 +509,7 @@ class nsTArray_base {
Header* Hdr() const MOZ_NONNULL_RETURN { return mHdr; }
Header** PtrToHdr() MOZ_NONNULL_RETURN { return &mHdr; }
- static Header* EmptyHdr() MOZ_NONNULL_RETURN {
+ static constexpr Header* EmptyHdr() MOZ_NONNULL_RETURN {
return const_cast<Header*>(&sEmptyTArrayHeader);
}
@@ -2613,7 +2613,7 @@ class MOZ_GSL_OWNER nsTArray
using typename base_type::size_type;
using typename base_type::value_type;
- nsTArray() {}
+ constexpr nsTArray() {}
explicit nsTArray(size_type aCapacity) : base_type(aCapacity) {}
MOZ_IMPLICIT nsTArray(std::initializer_list<E> aIL) {
AppendElements(aIL.begin(), aIL.size());
diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp
@@ -2900,7 +2900,8 @@ static bool sWaitingForHiddenWindowToLoadNativeMenus =
# endif
;
-MOZ_RUNINIT static nsTArray<LoadNativeMenusListener> sLoadNativeMenusListeners;
+MOZ_CONSTINIT static nsTArray<LoadNativeMenusListener>
+ sLoadNativeMenusListeners;
static void BeginLoadNativeMenus(Document* aDoc, nsIWidget* aParentWindow);