Bug 1691913 - Add some convenience methods to LookupResult and EntryHandle. r=xpcom-reviewers,nika

Differential Revision: https://phabricator.services.mozilla.com/D105475
This commit is contained in:
Simon Giesecke 2021-03-01 09:59:29 +00:00
Родитель 2c98fb147b
Коммит b399a8194c
14 изменённых файлов: 52 добавлений и 26 удалений

Просмотреть файл

@ -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);
@ -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;

Просмотреть файл

@ -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);
@ -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,

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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:

Просмотреть файл

@ -142,7 +142,7 @@ class GMPDiskStorage : public GMPStorage {
.get();
}
return entry.Data().get();
return entry->get();
});
if (!record) {
return GMPGenericErr;

Просмотреть файл

@ -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;

Просмотреть файл

@ -2258,7 +2258,7 @@ gfxPlatformFontList::PrefFontList* gfxFcPlatformFontList::FindGenericFamilies(
entry.Insert(std::move(prefFonts));
}
return entry.Data().get();
return entry->get();
});
}

Просмотреть файл

@ -127,7 +127,7 @@ gfxSVGGlyphsDocument* gfxSVGGlyphs::FindOrCreateGlyphsDocument(
return nullptr;
}
return glyphDocsEntry.Data().get();
return glyphDocsEntry->get();
});
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -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};
});
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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);

Просмотреть файл

@ -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.

Просмотреть файл

@ -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(); }
};
/**
@ -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;