Bug 1689218 - Rename nsBaseHashtable::GetAndRemove to Extract. r=necko-reviewers,dragana

First, it should be called "Lookup" rather than "Get" because it returns
DataType (rather than UserDataType), but that would still be confusing,
since as opposed to other Lookup* methods, it does not return a DataType&
(and obviously, it can't). So "Extract" seems to be a better name, cf.
mozilla::Maybe::extract.

Differential Revision: https://phabricator.services.mozilla.com/D105471
This commit is contained in:
Simon Giesecke 2021-02-22 12:07:48 +00:00
Родитель c5f7800f35
Коммит 7c931c97c4
14 изменённых файлов: 25 добавлений и 26 удалений

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

@ -208,8 +208,7 @@ void MsaaIdGenerator::ReleaseContentProcessIDFor(
return;
}
Maybe<uint32_t> mapping =
sContentParentIdMap->GetAndRemove(aIPCContentProcessID);
Maybe<uint32_t> mapping = sContentParentIdMap->Extract(aIPCContentProcessID);
if (!mapping) {
// Since Content IDs are generated lazily, ContentParent might attempt
// to release an ID that was never allocated to begin with.

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

@ -16,7 +16,7 @@ static StaticRefPtr<ChildProcessChannelListener> sCPCLSingleton;
void ChildProcessChannelListener::RegisterCallback(uint64_t aIdentifier,
Callback&& aCallback) {
if (auto args = mChannelArgs.GetAndRemove(aIdentifier)) {
if (auto args = mChannelArgs.Extract(aIdentifier)) {
nsresult rv =
aCallback(args->mLoadState, std::move(args->mStreamFilterEndpoints),
args->mTiming);
@ -30,7 +30,7 @@ void ChildProcessChannelListener::OnChannelReady(
nsDocShellLoadState* aLoadState, uint64_t aIdentifier,
nsTArray<Endpoint>&& aStreamFilterEndpoints, nsDOMNavigationTiming* aTiming,
Resolver&& aResolver) {
if (auto callback = mCallbacks.GetAndRemove(aIdentifier)) {
if (auto callback = mCallbacks.Extract(aIdentifier)) {
nsresult rv =
(*callback)(aLoadState, std::move(aStreamFilterEndpoints), aTiming);
aResolver(rv);

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

@ -82,7 +82,7 @@ bool ContentProcessManager::RegisterRemoteFrame(BrowserParent* aChildBp) {
void ContentProcessManager::UnregisterRemoteFrame(const TabId& aChildTabId) {
MOZ_ASSERT(NS_IsMainThread());
auto childBp = mBrowserParentMap.GetAndRemove(aChildTabId);
auto childBp = mBrowserParentMap.Extract(aChildTabId);
MOZ_DIAGNOSTIC_ASSERT(childBp);
// Clear the corresponding keepalive which was added in `RegisterRemoteFrame`.

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

@ -324,7 +324,7 @@ void JSActor::ReceiveQueryReply(JSContext* aCx,
return;
}
Maybe<PendingQuery> query = mPendingQueries.GetAndRemove(aMetadata.queryId());
Maybe<PendingQuery> query = mPendingQueries.Extract(aMetadata.queryId());
if (NS_WARN_IF(!query)) {
aRv.ThrowUnknownError("Received reply for non-pending query");
return;

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

@ -395,7 +395,7 @@ ipc::IPCResult ChromiumCDMParent::RecvOnResolveNewSessionPromise(
return IPC_OK();
}
Maybe<uint32_t> token = mPromiseToCreateSessionToken.GetAndRemove(aPromiseId);
Maybe<uint32_t> token = mPromiseToCreateSessionToken.Extract(aPromiseId);
if (token.isNothing()) {
RejectPromiseWithStateError(aPromiseId,
"Lost session token for new session."_ns);

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

@ -439,7 +439,7 @@ nsresult CrossProcessPaint::ResolveInternal(dom::TabId aTabId,
CPP_LOG("Resolving fragment %" PRIu64 ".\n", (uint64_t)aTabId);
Maybe<PaintFragment> fragment = mReceivedFragments.GetAndRemove(aTabId);
Maybe<PaintFragment> fragment = mReceivedFragments.Extract(aTabId);
if (!fragment) {
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
}

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

@ -26,7 +26,7 @@ bool nsGenConList::DestroyNodesFor(nsIFrame* aFrame) {
// each frame is mapped to only one (nsIContent, pseudoType) pair,
// and the nodes in the linked list are put in the tree order based
// on that pair and offset inside frame.
nsGenConNode* node = mNodes.GetAndRemove(aFrame).valueOr(nullptr);
nsGenConNode* node = mNodes.Extract(aFrame).valueOr(nullptr);
if (!node) {
return false;
}

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

@ -313,7 +313,7 @@ void SharedStyleSheetCache::LoadCompletedInternal(
if (aData.mIsLoading) {
MOZ_ASSERT(aCache);
SheetLoadDataHashKey key(aData);
Maybe<SheetLoadData*> loadingData = aCache->mLoadingDatas.GetAndRemove(key);
Maybe<SheetLoadData*> loadingData = aCache->mLoadingDatas.Extract(key);
MOZ_DIAGNOSTIC_ASSERT(loadingData);
MOZ_DIAGNOSTIC_ASSERT(loadingData.value() == &aData);
Unused << loadingData;

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

@ -446,7 +446,7 @@ NS_IMETHODIMP NativeDNSResolverOverride::ClearHostOverride(
const nsACString& aHost) {
AutoWriteLock lock(mLock);
mCnames.Remove(aHost);
auto overrides = mOverrides.GetAndRemove(aHost);
auto overrides = mOverrides.Extract(aHost);
if (!overrides) {
return NS_OK;
}

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

@ -441,7 +441,7 @@ void SocketProcessChild::RemoveDataBridgeFromMap(uint64_t aChannelId) {
Maybe<RefPtr<BackgroundDataBridgeParent>>
SocketProcessChild::GetAndRemoveDataBridge(uint64_t aChannelId) {
MutexAutoLock lock(mMutex);
return mBackgroundDataBridgeMap.GetAndRemove(aChannelId);
return mBackgroundDataBridgeMap.Extract(aChannelId);
}
mozilla::ipc::IPCResult SocketProcessChild::RecvClearSessionCache() {

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

@ -560,7 +560,7 @@ inline nsScriptObjectTracer* JSHolderMap::Get(void* aHolder) const {
return entry->mTracer;
}
inline nsScriptObjectTracer* JSHolderMap::GetAndRemove(void* aHolder) {
inline nsScriptObjectTracer* JSHolderMap::Extract(void* aHolder) {
MOZ_ASSERT(aHolder);
auto ptr = mJSHolderMap.lookup(aHolder);
@ -1431,7 +1431,7 @@ struct ClearJSHolder : public TraceCallbacks {
};
void CycleCollectedJSRuntime::RemoveJSHolder(void* aHolder) {
nsScriptObjectTracer* tracer = mJSHolders.GetAndRemove(aHolder);
nsScriptObjectTracer* tracer = mJSHolders.Extract(aHolder);
if (tracer) {
// Bug 1531951: The analysis can't see through the virtual call but we know
// that the ClearJSHolder tracer will never GC.

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

@ -98,7 +98,7 @@ class JSHolderMap {
bool Has(void* aHolder) const;
nsScriptObjectTracer* Get(void* aHolder) const;
nsScriptObjectTracer* GetAndRemove(void* aHolder);
nsScriptObjectTracer* Extract(void* aHolder);
void Put(void* aHolder, nsScriptObjectTracer* aTracer, JS::Zone* aZone);
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;

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

@ -247,7 +247,7 @@ class nsBaseHashtable
* into *aData. Return true if found.
*
* This overload can only be used if DataType is default-constructible. Use
* the single-argument Remove or GetAndRemove with non-default-constructible
* the single-argument Remove or Extract with non-default-constructible
* DataType.
*
* @param aKey the key to remove from the hashtable
@ -293,7 +293,7 @@ class nsBaseHashtable
* @return the found value, or Nothing if no entry was found with the
* given key.
*/
[[nodiscard]] mozilla::Maybe<DataType> GetAndRemove(KeyType aKey) {
[[nodiscard]] mozilla::Maybe<DataType> Extract(KeyType aKey) {
mozilla::Maybe<DataType> value;
if (EntryType* ent = this->GetEntry(aKey)) {
value.emplace(std::move(ent->mData));

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

@ -380,7 +380,7 @@ struct DefaultConstructible_DefaultConstructible {
static constexpr uint32_t kExpectedAddRefCnt_Put_Rvalue_Fallible = 1;
static constexpr uint32_t kExpectedAddRefCnt_Remove_OutputParam = 1;
static constexpr uint32_t kExpectedAddRefCnt_Remove = 1;
static constexpr uint32_t kExpectedAddRefCnt_GetAndRemove = 1;
static constexpr uint32_t kExpectedAddRefCnt_Extract = 1;
static constexpr uint32_t kExpectedAddRefCnt_RemoveIf = 1;
static constexpr uint32_t kExpectedAddRefCnt_Lookup = 1;
static constexpr uint32_t kExpectedAddRefCnt_Lookup_Remove = 1;
@ -415,7 +415,7 @@ struct NonDefaultConstructible_NonDefaultConstructible {
static constexpr uint32_t kExpectedAddRefCnt_Put_Rvalue = 2;
static constexpr uint32_t kExpectedAddRefCnt_Put_Rvalue_Fallible = 2;
static constexpr uint32_t kExpectedAddRefCnt_Remove = 2;
static constexpr uint32_t kExpectedAddRefCnt_GetAndRemove = 3;
static constexpr uint32_t kExpectedAddRefCnt_Extract = 3;
static constexpr uint32_t kExpectedAddRefCnt_RemoveIf = 2;
static constexpr uint32_t kExpectedAddRefCnt_Lookup = 2;
static constexpr uint32_t kExpectedAddRefCnt_Lookup_Remove = 2;
@ -447,7 +447,7 @@ struct NonDefaultConstructible_MovingNonDefaultConstructible {
static constexpr uint32_t kExpectedAddRefCnt_Put_Rvalue = 1;
static constexpr uint32_t kExpectedAddRefCnt_Put_Rvalue_Fallible = 1;
static constexpr uint32_t kExpectedAddRefCnt_Remove = 1;
static constexpr uint32_t kExpectedAddRefCnt_GetAndRemove = 2;
static constexpr uint32_t kExpectedAddRefCnt_Extract = 2;
static constexpr uint32_t kExpectedAddRefCnt_RemoveIf = 1;
static constexpr uint32_t kExpectedAddRefCnt_Lookup = 1;
static constexpr uint32_t kExpectedAddRefCnt_Lookup_Remove = 1;
@ -800,11 +800,11 @@ TYPED_TEST_P(BaseHashtableTest, Remove) {
EXPECT_TRUE(res);
}
TYPED_TEST_P(BaseHashtableTest, GetAndRemove) {
TYPED_TEST_P(BaseHashtableTest, Extract) {
auto table =
MakeBaseHashtable<TypeParam>(TypeParam::kExpectedAddRefCnt_GetAndRemove);
MakeBaseHashtable<TypeParam>(TypeParam::kExpectedAddRefCnt_Extract);
auto maybeData = table.GetAndRemove(1);
auto maybeData = table.Extract(1);
EXPECT_TRUE(maybeData);
EXPECT_EQ(maybeData->CharRef()->GetChar(), 42u);
}
@ -995,9 +995,9 @@ REGISTER_TYPED_TEST_CASE_P(
GetOrInsert_Default, GetOrInsert_NonDefault,
GetOrInsert_NonDefault_AlreadyPresent, GetOrInsertWith,
GetOrInsertWith_AlreadyPresent, Put, Put_Fallible, Put_Rvalue,
Put_Rvalue_Fallible, Remove_OutputParam, Remove, GetAndRemove, RemoveIf,
Lookup, Lookup_Remove, WithEntryHandle_NoOp,
WithEntryHandle_NotFound_OrInsert, WithEntryHandle_NotFound_OrInsertFrom,
Put_Rvalue_Fallible, Remove_OutputParam, Remove, Extract, RemoveIf, Lookup,
Lookup_Remove, WithEntryHandle_NoOp, WithEntryHandle_NotFound_OrInsert,
WithEntryHandle_NotFound_OrInsertFrom,
WithEntryHandle_NotFound_OrInsertFrom_Exists,
WithEntryHandle_NotFound_OrRemove, WithEntryHandle_NotFound_OrRemove_Exists,
Iter, ConstIter, begin_end, cbegin_cend, Clear, ShallowSizeOfExcludingThis,