diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 52d0a7772ca3..8832db3911b6 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -469,6 +469,8 @@ struct Loader::Sheets { // A cache hit or miss. It is a miss if the `StyleSheet` is null. using CacheResult = Tuple, SheetState>; CacheResult Lookup(SheetLoadDataHashKey&, bool aSyncLoad); + + size_t SizeOfIncludingThis(MallocSizeOf) const; }; RefPtr Loader::Sheets::LookupInline(const nsAString& aBuffer) { @@ -578,6 +580,39 @@ auto Loader::Sheets::Lookup(SheetLoadDataHashKey& aKey, bool aSyncLoad) return {}; } +size_t Loader::Sheets::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { + size_t n = aMallocSizeOf(this); + + n += mCompleteSheets.ShallowSizeOfExcludingThis(aMallocSizeOf); + for (auto iter = mCompleteSheets.ConstIter(); !iter.Done(); iter.Next()) { + // If the sheet has a parent, then its parent will report it so we don't + // have to worry about it here. Likewise, if aSheet has an owning node, then + // the document that node is in will report it. + const StyleSheet* sheet = iter.UserData(); + if (!sheet->GetOwnerNode() && !sheet->GetParentSheet()) { + n += sheet->SizeOfIncludingThis(aMallocSizeOf); + } + } + + n += mInlineSheets.ShallowSizeOfExcludingThis(aMallocSizeOf); + for (auto iter = mInlineSheets.ConstIter(); !iter.Done(); iter.Next()) { + n += iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf); + // If the sheet has a parent, then its parent will report it so we don't + // have to worry about it here. + const StyleSheet* sheet = iter.UserData(); + MOZ_ASSERT(!sheet->GetParentSheet(), "How did an @import rule end up here?"); + if (!sheet->GetOwnerNode()) { + n += sheet->SizeOfIncludingThis(aMallocSizeOf); + } + } + + // Measurement of the following members may be added later if DMD finds it is + // worthwhile: + // - mLoadingDatas: transient, and should be small + // - mPendingDatas: transient, and should be small + return n; +} + /************************* * Loader Implementation * *************************/ @@ -2440,28 +2475,16 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Loader, AddRef) NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(Loader, Release) -size_t Loader::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { +size_t Loader::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { size_t n = aMallocSizeOf(this); if (mSheets) { - n += mSheets->mCompleteSheets.ShallowSizeOfExcludingThis(aMallocSizeOf); - for (auto iter = mSheets->mCompleteSheets.ConstIter(); !iter.Done(); - iter.Next()) { - // If aSheet has a parent, then its parent will report it so we don't - // have to worry about it here. Likewise, if aSheet has an owning node, - // then the document that node is in will report it. - const StyleSheet* sheet = iter.UserData(); - n += (sheet->GetOwnerNode() || sheet->GetParentSheet()) - ? 0 - : sheet->SizeOfIncludingThis(aMallocSizeOf); - } + n += mSheets->SizeOfIncludingThis(aMallocSizeOf); } n += mObservers.ShallowSizeOfExcludingThis(aMallocSizeOf); // Measurement of the following members may be added later if DMD finds it is // worthwhile: - // - mLoadingDatas: transient, and should be small - // - mPendingDatas: transient, and should be small // - mPostedEvents: transient, and should be small // // The following members aren't measured: