Skip to content

Commit

Permalink
Bug 1691913 - Add some convenience methods to LookupResult and EntryH…
Browse files Browse the repository at this point in the history
…andle. r=xpcom-reviewers,nika

Differential Revision: https://phabricator.services.mozilla.com/D105475
  • Loading branch information
sigiesec committed Mar 1, 2021
1 parent 2c98fb1 commit b399a81
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docshell/base/BaseHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void BaseHistory::RegisterVisitedCallback(nsIURI* aURI, Link* aLink) {
// Obtain our array of observers for this URI.
auto* const links =
mTrackedURIs.WithEntryHandle(aURI, [&](auto&& entry) -> ObservingLinks* {
MOZ_DIAGNOSTIC_ASSERT(!entry || !entry.Data().mLinks.IsEmpty(),
MOZ_DIAGNOSTIC_ASSERT(!entry || !entry->mLinks.IsEmpty(),
"An empty key was kept around in our hashtable!");
if (!entry) {
ScheduleVisitedQuery(aURI);
Expand Down Expand Up @@ -152,7 +152,7 @@ void BaseHistory::UnregisterVisitedCallback(nsIURI* aURI, Link* aLink) {
return;
}

ObserverArray& observers = entry.Data().mLinks;
ObserverArray& observers = entry->mLinks;
if (!observers.RemoveElement(aLink)) {
MOZ_ASSERT_UNREACHABLE("Trying to unregister node that wasn't registered!");
return;
Expand Down
4 changes: 2 additions & 2 deletions dom/html/HTMLFormElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ nsresult HTMLFormElement::RemoveElementFromTableInternal(

// If it's not a content node then it must be a RadioNodeList.
MOZ_ASSERT(nsCOMPtr<RadioNodeList>(do_QueryInterface(entry.Data())));
auto* list = static_cast<RadioNodeList*>(entry.Data().get());
auto* list = static_cast<RadioNodeList*>(entry->get());

list->RemoveElement(aChild);

Expand Down Expand Up @@ -2293,7 +2293,7 @@ nsresult HTMLFormElement::AddElementToTableInternal(
} else {
// There's already a list in the hash, add the child to the list.
MOZ_ASSERT(nsCOMPtr<RadioNodeList>(do_QueryInterface(entry.Data())));
auto* list = static_cast<RadioNodeList*>(entry.Data().get());
auto* list = static_cast<RadioNodeList*>(entry->get());

NS_ASSERTION(
list->Length() > 1,
Expand Down
18 changes: 9 additions & 9 deletions dom/ipc/StringTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ class StringTableBuilder {
using ElemType = typename StringType::char_type;

StringTableEntry Add(const StringType& aKey) {
return mEntries.WithEntryHandle(
aKey, [&](auto&& entry) -> StringTableEntry {
entry.OrInsertWith([&]() {
Entry newEntry{mSize, aKey};
mSize += aKey.Length() + 1;
return mEntries.WithEntryHandle(aKey,
[&](auto&& entry) -> StringTableEntry {
entry.OrInsertWith([&]() {
Entry newEntry{mSize, aKey};
mSize += aKey.Length() + 1;

return newEntry;
});
return newEntry;
});

return {entry.Data().mOffset, aKey.Length()};
});
return {entry->mOffset, aKey.Length()};
});
}

void Write(const RangedPtr<uint8_t>& aBuffer) {
Expand Down
2 changes: 1 addition & 1 deletion dom/localstorage/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3445,7 +3445,7 @@ void DatastoreWriteOptimizer::ApplyAndReset(
LSItemInfo& item = aOrderedItems[index];

if (auto entry = mWriteInfos.Lookup(item.key())) {
WriteInfo* writeInfo = entry.Data().get();
WriteInfo* writeInfo = entry->get();

switch (writeInfo->GetType()) {
case WriteInfo::DeleteItem:
Expand Down
2 changes: 1 addition & 1 deletion dom/media/gmp/GMPDiskStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class GMPDiskStorage : public GMPStorage {
.get();
}

return entry.Data().get();
return entry->get();
});
if (!record) {
return GMPGenericErr;
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/ImageContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ TextureClient* SourceSurfaceImage::GetTextureClient(
return mTextureClients.WithEntryHandle(
aKnowsCompositor->GetSerial(), [&](auto&& entry) -> TextureClient* {
if (entry) {
return entry.Data().get();
return entry->get();
}

RefPtr<TextureClient> textureClient;
Expand Down
2 changes: 1 addition & 1 deletion gfx/thebes/gfxFcPlatformFontList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,7 @@ gfxPlatformFontList::PrefFontList* gfxFcPlatformFontList::FindGenericFamilies(

entry.Insert(std::move(prefFonts));
}
return entry.Data().get();
return entry->get();
});
}

Expand Down
2 changes: 1 addition & 1 deletion gfx/thebes/gfxSVGGlyphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ gfxSVGGlyphsDocument* gfxSVGGlyphs::FindOrCreateGlyphsDocument(
return nullptr;
}

return glyphDocsEntry.Data().get();
return glyphDocsEntry->get();
});
}

Expand Down
4 changes: 2 additions & 2 deletions hal/HalWakeLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ void ModifyWakeLock(const nsAString& aTopic, hal::WakeLockControl aLockAdjust,
entry.Insert(MakeUnique<ProcessLockTable>());
} else {
Unused << entry.Data()->Get(aProcessID, &processCount);
CountWakeLocks(entry.Data().get(), &totalCount);
CountWakeLocks(entry->get(), &totalCount);
}
return entry.Data().get();
return entry->get();
});

MOZ_ASSERT(processCount.numLocks >= processCount.numHidden);
Expand Down
2 changes: 1 addition & 1 deletion modules/libpref/SharedPrefMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class MOZ_RAII SharedPrefMapBuilder {
return mDefaultEntries.WithEntryHandle(aDefaultValue, [&](auto&& entry) {
entry.OrInsertWith([&] { return Entry{index, false, aDefaultValue}; });

return ValueIdx{entry.Data().mIndex, false};
return ValueIdx{entry->mIndex, false};
});
}

Expand Down
2 changes: 1 addition & 1 deletion netwerk/base/SSLTokensCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ nsresult SSLTokensCache::Put(const nsACString& aKey, const uint8_t* aToken,
entry.Data()->Reset();
}

return entry.Data().get();
return entry->get();
});

rec->mExpirationTime = aExpirationTime;
Expand Down
5 changes: 2 additions & 3 deletions toolkit/components/places/History.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,9 +1843,8 @@ History::VisitURI(nsIWidget* aWidget, nsIURI* aURI, nsIURI* aLastVisitedURI,
auto entry = mRecentlyVisitedURIs.Lookup(aURI);
// Check if the entry exists and is younger than
// RECENTLY_VISITED_URIS_MAX_AGE.
if (entry &&
(PR_Now() - entry.Data().mTime) < RECENTLY_VISITED_URIS_MAX_AGE) {
bool wasHidden = entry.Data().mHidden;
if (entry && (PR_Now() - entry->mTime) < RECENTLY_VISITED_URIS_MAX_AGE) {
bool wasHidden = entry->mHidden;
// Regardless of whether we store the visit or not, we must update the
// stored visit time.
AppendToRecentlyVisitedURIs(aURI, place.hidden);
Expand Down
2 changes: 1 addition & 1 deletion xpcom/base/nsINIParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ nsresult nsINIParser::SetString(const char* aSection, const char* aKey,
return;
}

INIValue* v = entry.Data().get();
INIValue* v = entry->get();

// Check whether this key has already been specified; overwrite
// if so, or append if not.
Expand Down
27 changes: 27 additions & 0 deletions xpcom/ds/nsBaseHashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,25 @@ class nsBaseHashtable
MOZ_ASSERT(!!*this, "must have an entry to access its value");
return mEntry->mData;
}

[[nodiscard]] const DataType& Data() const {
MOZ_ASSERT(!!*this, "must have an entry to access its value");
return mEntry->mData;
}

[[nodiscard]] DataType* DataPtrOrNull() {
return static_cast<bool>(*this) ? &mEntry->mData : nullptr;
}

[[nodiscard]] const DataType* DataPtrOrNull() const {
return static_cast<bool>(*this) ? &mEntry->mData : nullptr;
}

[[nodiscard]] DataType* operator->() { return &Data(); }
[[nodiscard]] const DataType* operator->() const { return &Data(); }

[[nodiscard]] DataType& operator*() { return Data(); }
[[nodiscard]] const DataType& operator*() const { return Data(); }
};

/**
Expand Down Expand Up @@ -548,6 +567,14 @@ class nsBaseHashtable
*/
[[nodiscard]] DataType& Data() { return Entry()->mData; }

[[nodiscard]] DataType* DataPtrOrNull() {
return static_cast<bool>(*this) ? &Data() : nullptr;
}

[[nodiscard]] DataType* operator->() { return &Data(); }

[[nodiscard]] DataType& operator*() { return Data(); }

private:
friend class nsBaseHashtable;

Expand Down

0 comments on commit b399a81

Please sign in to comment.