Skip to content

Commit

Permalink
Bug 1640839 - Add some helpers for enums to calculate the size and us…
Browse files Browse the repository at this point in the history
…e it in EnumeratedArray. r=glandium,jgilbert,media-playback-reviewers,padenot

Differential Revision: https://phabricator.services.mozilla.com/D201334
  • Loading branch information
petervanderbeken committed Mar 2, 2024
1 parent 9c8d00b commit 2b747df
Show file tree
Hide file tree
Showing 53 changed files with 189 additions and 126 deletions.
2 changes: 1 addition & 1 deletion dom/animation/EffectCompositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class EffectCompositor {
// indicate that the style rule on the element is out of date but without
// posting a restyle to update it.
EnumeratedArray<CascadeLevel, nsTHashMap<PseudoElementHashEntry, bool>,
CascadeLevel(kCascadeLevelCount)>
kCascadeLevelCount>
mElementsToRestyle;

bool mIsInPreTraverse = false;
Expand Down
2 changes: 1 addition & 1 deletion dom/base/FlushType.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum class FlushType : uint8_t {

// Flush type strings that will be displayed in the profiler
// clang-format off
const EnumeratedArray<FlushType, const char*, FlushType::Count>
const EnumeratedArray<FlushType, const char*, size_t(FlushType::Count)>
kFlushTypeNames = {
"",
"Event",
Expand Down
8 changes: 5 additions & 3 deletions dom/canvas/CanvasRenderingContext2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -1008,9 +1008,11 @@ class CanvasRenderingContext2D : public nsICanvasRenderingContextInternal,
RefPtr<nsAtom> fontLanguage;
nsFont fontFont;

EnumeratedArray<Style, RefPtr<CanvasGradient>, Style::MAX> gradientStyles;
EnumeratedArray<Style, RefPtr<CanvasPattern>, Style::MAX> patternStyles;
EnumeratedArray<Style, nscolor, Style::MAX> colorStyles;
EnumeratedArray<Style, RefPtr<CanvasGradient>, size_t(Style::MAX)>
gradientStyles;
EnumeratedArray<Style, RefPtr<CanvasPattern>, size_t(Style::MAX)>
patternStyles;
EnumeratedArray<Style, nscolor, size_t(Style::MAX)> colorStyles;

nsCString font;
CanvasTextAlign textAlign = CanvasTextAlign::Start;
Expand Down
2 changes: 1 addition & 1 deletion dom/canvas/WebGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ class WebGLContext : public VRefCounted, public SupportsWeakPtr {
// WebGL extensions (implemented in WebGLContextExtensions.cpp)

EnumeratedArray<WebGLExtensionID, std::unique_ptr<WebGLExtensionBase>,
WebGLExtensionID::Max>
size_t(WebGLExtensionID::Max)>
mExtensions;

public:
Expand Down
6 changes: 3 additions & 3 deletions dom/media/ipc/RemoteDecoderManagerChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ using namespace gfx;
// should be launched serially. Protects sLaunchPromise
StaticMutex sLaunchMutex;
static EnumeratedArray<RemoteDecodeIn, StaticRefPtr<GenericNonExclusivePromise>,
RemoteDecodeIn::SENTINEL>
size_t(RemoteDecodeIn::SENTINEL)>
sLaunchPromises MOZ_GUARDED_BY(sLaunchMutex);

// Only modified on the main-thread, read on any thread. While it could be read
Expand All @@ -62,7 +62,7 @@ static StaticDataMutex<StaticRefPtr<nsIThread>>

// Only accessed from sRemoteDecoderManagerChildThread
static EnumeratedArray<RemoteDecodeIn, StaticRefPtr<RemoteDecoderManagerChild>,
RemoteDecodeIn::SENTINEL>
size_t(RemoteDecodeIn::SENTINEL)>
sRemoteDecoderManagerChildForProcesses;

static StaticAutoPtr<nsTArray<RefPtr<Runnable>>> sRecreateTasks;
Expand All @@ -71,7 +71,7 @@ static StaticAutoPtr<nsTArray<RefPtr<Runnable>>> sRecreateTasks;
// processes.
StaticMutex sProcessSupportedMutex;
static EnumeratedArray<RemoteDecodeIn, Maybe<media::MediaCodecsSupported>,
RemoteDecodeIn::SENTINEL>
size_t(RemoteDecodeIn::SENTINEL)>
sProcessSupported MOZ_GUARDED_BY(sProcessSupportedMutex);

class ShutdownObserver final : public nsIObserver {
Expand Down
2 changes: 1 addition & 1 deletion dom/media/mediasession/MediaSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MediaSession final : public nsIDocumentActivity, public nsWrapperCache {
RefPtr<MediaMetadata> mMediaMetadata;

EnumeratedArray<MediaSessionAction, RefPtr<MediaSessionActionHandler>,
MediaSessionAction::EndGuard_>
size_t(MediaSessionAction::EndGuard_)>
mActionHandlers;

// This is used as is a hint for the user agent to determine whether the
Expand Down
3 changes: 2 additions & 1 deletion dom/quota/QuotaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ class QuotaManager final : public BackgroundThreadObject {

nsCOMPtr<mozIStorageConnection> mStorageConnection;

EnumeratedArray<Client::Type, nsCString, Client::TYPE_MAX> mShutdownSteps;
EnumeratedArray<Client::Type, nsCString, size_t(Client::TYPE_MAX)>
mShutdownSteps;
LazyInitializedOnce<const TimeStamp> mShutdownStartedAt;

// Accesses to mQuotaManagerShutdownSteps must be protected by mQuotaMutex.
Expand Down
4 changes: 2 additions & 2 deletions dom/system/IOUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class IOUtils final {
};

template <typename T>
using PhaseArray =
EnumeratedArray<IOUtils::ShutdownPhase, T, IOUtils::ShutdownPhase::Count>;
using PhaseArray = EnumeratedArray<IOUtils::ShutdownPhase, T,
size_t(IOUtils::ShutdownPhase::Count)>;

static already_AddRefed<Promise> Read(GlobalObject& aGlobal,
const nsAString& aPath,
Expand Down
3 changes: 2 additions & 1 deletion dom/system/PathUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ class PathUtils::DirectoryCache final {
void ResolveWithDirectory(Promise* aPromise, const Directory aRequestedDir);

template <typename T>
using DirectoryArray = EnumeratedArray<Directory, T, Directory::Count>;
using DirectoryArray =
EnumeratedArray<Directory, T, size_t(Directory::Count)>;

DirectoryArray<nsString> mDirectories;
DirectoryArray<MozPromiseHolder<PopulateDirectoriesPromise>> mPromises;
Expand Down
2 changes: 1 addition & 1 deletion dom/xslt/xslt/txEXSLTFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ struct txEXSLTFunctionDescriptor {
};

static EnumeratedArray<txEXSLTType, txEXSLTFunctionDescriptor,
txEXSLTType::_LIMIT>
size_t(txEXSLTType::_LIMIT)>
descriptTable;

class txEXSLTFunctionCall : public FunctionCall {
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/ImageContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Image {

mozilla::EnumeratedArray<mozilla::layers::LayersBackend,
UniquePtr<ImageBackendData>,
mozilla::layers::LayersBackend::LAYERS_LAST>
size_t(mozilla::layers::LayersBackend::LAYERS_LAST)>
mBackendData;

void* mImplData;
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/ipc/VideoBridgeParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace mozilla::ipc;
using namespace mozilla::gfx;

using VideoBridgeTable = EnumeratedArray<VideoBridgeSource, VideoBridgeParent*,
VideoBridgeSource::_Count>;
size_t(VideoBridgeSource::_Count)>;

static StaticDataMutex<VideoBridgeTable> sVideoBridgeFromProcess(
"VideoBridges");
Expand Down
5 changes: 3 additions & 2 deletions gfx/thebes/gfxPlatformFontList.h
Original file line number Diff line number Diff line change
Expand Up @@ -1011,12 +1011,13 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
// When system-wide font lookup fails for a character, cache it to skip future
// searches. This is an array of bitsets, one for each FontVisibility level.
mozilla::EnumeratedArray<FontVisibility, gfxSparseBitSet,
FontVisibility::Count>
size_t(FontVisibility::Count)>
mCodepointsWithNoFonts MOZ_GUARDED_BY(mLock);

// the family to use for U+FFFD fallback, to avoid expensive search every time
// on pages with lots of problems
mozilla::EnumeratedArray<FontVisibility, FontFamily, FontVisibility::Count>
mozilla::EnumeratedArray<FontVisibility, FontFamily,
size_t(FontVisibility::Count)>
mReplacementCharFallbackFamily MOZ_GUARDED_BY(mLock);

// Sorted array of lowercased family names; use ContainsSorted to test
Expand Down
2 changes: 1 addition & 1 deletion ipc/glue/UtilityAudioDecoderChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ NS_IMETHODIMP UtilityAudioDecoderChildShutdownObserver::Observe(
NS_IMPL_ISUPPORTS(UtilityAudioDecoderChildShutdownObserver, nsIObserver);

static EnumeratedArray<SandboxingKind, StaticRefPtr<UtilityAudioDecoderChild>,
SandboxingKind::COUNT>
size_t(SandboxingKind::COUNT)>
sAudioDecoderChilds;

UtilityAudioDecoderChild::UtilityAudioDecoderChild(SandboxingKind aKind)
Expand Down
3 changes: 2 additions & 1 deletion ipc/glue/UtilityProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ class UtilityProcessManager final : public UtilityProcessHost::Listener {
~ProcessFields() = default;
};

EnumeratedArray<SandboxingKind, RefPtr<ProcessFields>, SandboxingKind::COUNT>
EnumeratedArray<SandboxingKind, RefPtr<ProcessFields>,
size_t(SandboxingKind::COUNT)>
mProcesses;

RefPtr<ProcessFields> GetProcess(SandboxingKind);
Expand Down
6 changes: 3 additions & 3 deletions js/public/RootingAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -981,12 +981,12 @@ enum class AutoGCRooterKind : uint8_t {
Limit
};

using RootedListHeads =
mozilla::EnumeratedArray<RootKind, js::StackRootedBase*, RootKind::Limit>;
using RootedListHeads = mozilla::EnumeratedArray<RootKind, js::StackRootedBase*,
size_t(RootKind::Limit)>;

using AutoRooterListHeads =
mozilla::EnumeratedArray<AutoGCRooterKind, AutoGCRooter*,
AutoGCRooterKind::Limit>;
size_t(AutoGCRooterKind::Limit)>;

// Superclass of JSContext which can be used for rooting data in use by the
// current thread but that does not provide all the functions of a JSContext.
Expand Down
5 changes: 3 additions & 2 deletions js/src/gc/AllocKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,14 @@ constexpr auto SomeAllocKinds(AllocKind first = AllocKind::FIRST,
// with each index corresponding to a particular alloc kind.
template <typename ValueType>
using AllAllocKindArray =
mozilla::EnumeratedArray<AllocKind, ValueType, AllocKind::LIMIT>;
mozilla::EnumeratedArray<AllocKind, ValueType, size_t(AllocKind::LIMIT)>;

// ObjectAllocKindArray<ValueType> gives an enumerated array of ValueTypes,
// with each index corresponding to a particular object alloc kind.
template <typename ValueType>
using ObjectAllocKindArray =
mozilla::EnumeratedArray<AllocKind, ValueType, AllocKind::OBJECT_LIMIT>;
mozilla::EnumeratedArray<AllocKind, ValueType,
size_t(AllocKind::OBJECT_LIMIT)>;

/*
* Map from C++ type to alloc kind for non-object types. JSObject does not have
Expand Down
4 changes: 2 additions & 2 deletions js/src/gc/Nursery.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ class Nursery {
};

using ProfileTimes = mozilla::EnumeratedArray<ProfileKey, mozilla::TimeStamp,
ProfileKey::KeyCount>;
size_t(ProfileKey::KeyCount)>;
using ProfileDurations =
mozilla::EnumeratedArray<ProfileKey, mozilla::TimeDuration,
ProfileKey::KeyCount>;
size_t(ProfileKey::KeyCount)>;

// Calculate the promotion rate of the most recent minor GC.
// The valid_for_tenuring parameter is used to return whether this
Expand Down
4 changes: 2 additions & 2 deletions js/src/gc/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ struct PhaseInfo {
};

// A table of PhaseInfo indexed by Phase.
using PhaseTable = EnumeratedArray<Phase, PhaseInfo, Phase::LIMIT>;
using PhaseTable = EnumeratedArray<Phase, PhaseInfo, size_t(Phase::LIMIT)>;

// A table of PhaseKindInfo indexed by PhaseKind.
using PhaseKindTable =
EnumeratedArray<PhaseKind, PhaseKindInfo, PhaseKind::LIMIT>;
EnumeratedArray<PhaseKind, PhaseKindInfo, size_t(PhaseKind::LIMIT)>;

#include "gc/StatsPhasesGenerated.inc"

Expand Down
2 changes: 1 addition & 1 deletion js/src/gc/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ struct Statistics {

template <typename IndexType, typename ValueType, IndexType SizeAsEnumValue>
using EnumeratedArray =
mozilla::EnumeratedArray<IndexType, ValueType, SizeAsEnumValue>;
mozilla::EnumeratedArray<IndexType, ValueType, size_t(SizeAsEnumValue)>;

using TimeDuration = mozilla::TimeDuration;
using TimeStamp = mozilla::TimeStamp;
Expand Down
4 changes: 2 additions & 2 deletions js/src/jit/CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2167,8 +2167,8 @@ class CreateDependentString {
NotInlineString,
Count
};
mozilla::EnumeratedArray<FallbackKind, Label, FallbackKind::Count> fallbacks_,
joins_;
mozilla::EnumeratedArray<FallbackKind, Label, size_t(FallbackKind::Count)>
fallbacks_, joins_;

public:
CreateDependentString(CharEncoding encoding, Register string, Register temp1,
Expand Down
3 changes: 2 additions & 1 deletion js/src/jit/ExecutableAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class ExecutablePool {
bool m_mark : 1;

// Number of bytes currently allocated for each CodeKind.
mozilla::EnumeratedArray<CodeKind, size_t, CodeKind::Count> m_codeBytes;
mozilla::EnumeratedArray<CodeKind, size_t, size_t(CodeKind::Count)>
m_codeBytes;

public:
void release(bool willDestroy = false);
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/IonOptimizationLevels.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class OptimizationInfo {
class OptimizationLevelInfo {
private:
mozilla::EnumeratedArray<OptimizationLevel, OptimizationInfo,
OptimizationLevel::Count>
size_t(OptimizationLevel::Count)>
infos_;

public:
Expand Down
11 changes: 6 additions & 5 deletions js/src/jit/JitRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ enum class BailoutReturnKind {
// is stored in JitRuntime and generated when creating the JitRuntime.
class BaselineICFallbackCode {
JitCode* code_ = nullptr;
using OffsetArray = mozilla::EnumeratedArray<BaselineICFallbackKind, uint32_t,
BaselineICFallbackKind::Count>;
using OffsetArray =
mozilla::EnumeratedArray<BaselineICFallbackKind, uint32_t,
size_t(BaselineICFallbackKind::Count)>;
OffsetArray offsets_ = {};

// Keep track of offset into various baseline stubs' code at return
// point from called script.
using BailoutReturnArray =
mozilla::EnumeratedArray<BailoutReturnKind, uint32_t,
BailoutReturnKind::Count>;
size_t(BailoutReturnKind::Count)>;
BailoutReturnArray bailoutReturnOffsets_ = {};

public:
Expand Down Expand Up @@ -175,12 +176,12 @@ class JitRuntime {

// Thunk to do a generic call from Ion.
mozilla::EnumeratedArray<IonGenericCallKind, WriteOnceData<uint32_t>,
IonGenericCallKind::Count>
size_t(IonGenericCallKind::Count)>
ionGenericCallStubOffset_;

// Thunk used by the debugger for breakpoint and step mode.
mozilla::EnumeratedArray<DebugTrapHandlerKind, WriteOnceData<JitCode*>,
DebugTrapHandlerKind::Count>
size_t(DebugTrapHandlerKind::Count)>
debugTrapHandlers_;

// BaselineInterpreter state.
Expand Down
3 changes: 2 additions & 1 deletion js/src/jit/JitZone.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class JitZone {
Count
};

mozilla::EnumeratedArray<StubIndex, WeakHeapPtr<JitCode*>, StubIndex::Count>
mozilla::EnumeratedArray<StubIndex, WeakHeapPtr<JitCode*>,
size_t(StubIndex::Count)>
stubs_;

mozilla::Maybe<IonCompilationId> currentCompilationId_;
Expand Down
3 changes: 2 additions & 1 deletion js/src/jit/WarpCacheIRTranspiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class MOZ_RAII WarpCacheIRTranspiler : public WarpBuilderShared {

// Array mapping call arguments to OperandId.
using ArgumentKindArray =
mozilla::EnumeratedArray<ArgumentKind, OperandId, ArgumentKind::NumKinds>;
mozilla::EnumeratedArray<ArgumentKind, OperandId,
size_t(ArgumentKind::NumKinds)>;
ArgumentKindArray argumentOperandIds_;

void setArgumentId(ArgumentKind kind, OperandId id) {
Expand Down
4 changes: 2 additions & 2 deletions js/src/util/StructuredSpewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ class StructuredSpewer {
// Globally selected channel.
StructuredSpewFilter selectedChannel_;

using NameArray =
mozilla::EnumeratedArray<SpewChannel, const char*, SpewChannel::Count>;
using NameArray = mozilla::EnumeratedArray<SpewChannel, const char*,
size_t(SpewChannel::Count)>;
// Channel Names
static NameArray const names_;

Expand Down
10 changes: 5 additions & 5 deletions js/src/vm/GlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class GlobalObjectData {
HeapPtr<JSObject*> constructor;
HeapPtr<JSObject*> prototype;
};
using CtorArray =
mozilla::EnumeratedArray<JSProtoKey, ConstructorWithProto, JSProto_LIMIT>;
using CtorArray = mozilla::EnumeratedArray<JSProtoKey, ConstructorWithProto,
size_t(JSProto_LIMIT)>;
CtorArray builtinConstructors;

// Built-in prototypes for this global. Note that this is different from the
Expand All @@ -154,8 +154,8 @@ class GlobalObjectData {

Limit
};
using ProtoArray =
mozilla::EnumeratedArray<ProtoKind, HeapPtr<JSObject*>, ProtoKind::Limit>;
using ProtoArray = mozilla::EnumeratedArray<ProtoKind, HeapPtr<JSObject*>,
size_t(ProtoKind::Limit)>;
ProtoArray builtinProtos;

HeapPtr<GlobalScope*> emptyGlobalScope;
Expand Down Expand Up @@ -197,7 +197,7 @@ class GlobalObjectData {
// AllocKind.
using PlainObjectShapeArray =
mozilla::EnumeratedArray<PlainObjectSlotsKind, HeapPtr<SharedShape*>,
PlainObjectSlotsKind::Limit>;
size_t(PlainObjectSlotsKind::Limit)>;
PlainObjectShapeArray plainObjectShapesWithDefaultProto;

// Shape for JSFunction with %Function.prototype% as proto, for both
Expand Down
3 changes: 2 additions & 1 deletion js/src/vm/HelperThreadState.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class GlobalHelperThreadState {
PromiseHelperTaskVector;

// Count of running task by each threadType.
mozilla::EnumeratedArray<ThreadType, size_t, ThreadType::THREAD_TYPE_MAX>
mozilla::EnumeratedArray<ThreadType, size_t,
size_t(ThreadType::THREAD_TYPE_MAX)>
runningTaskCount;
size_t totalCountRunningTasks;

Expand Down
2 changes: 1 addition & 1 deletion js/src/vm/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ struct JSRuntime {
// Heap GC roots for PersistentRooted pointers.
js::MainThreadData<mozilla::EnumeratedArray<
JS::RootKind, mozilla::LinkedList<js::PersistentRootedBase>,
JS::RootKind::Limit>>
size_t(JS::RootKind::Limit)>>
heapRoots;

void tracePersistentRoots(JSTracer* trc);
Expand Down
2 changes: 1 addition & 1 deletion js/src/wasm/WasmBuiltinModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class BuiltinModuleFunc {
class BuiltinModuleFuncs {
using Storage =
mozilla::EnumeratedArray<BuiltinModuleFuncId, BuiltinModuleFunc,
BuiltinModuleFuncId::Limit>;
size_t(BuiltinModuleFuncId::Limit)>;
Storage funcs_;

static BuiltinModuleFuncs* singleton_;
Expand Down
Loading

0 comments on commit 2b747df

Please sign in to comment.