Bug 1642949 - Replace uses of RemoveElementAt by RemoveLastElement/PopLastElement where possible. r=necko-reviewers,froydnj

Differential Revision: https://phabricator.services.mozilla.com/D78027
This commit is contained in:
Simon Giesecke 2020-06-10 10:46:14 +00:00
parent e8caef7a14
commit 82dc9b2271
44 changed files with 99 additions and 176 deletions

View File

@ -241,19 +241,23 @@ class MOZ_RAII AutoConstructionStackEntry final {
: mStack(aStack) {
MOZ_ASSERT(aElement->IsHTMLElement() || aElement->IsXULElement());
#ifdef DEBUG
mIndex = mStack.Length();
#endif
mStack.AppendElement(aElement);
}
~AutoConstructionStackEntry() {
MOZ_ASSERT(mIndex == mStack.Length() - 1,
"Removed element should be the last element");
mStack.RemoveElementAt(mIndex);
mStack.RemoveLastElement();
}
private:
nsTArray<RefPtr<Element>>& mStack;
#ifdef DEBUG
uint32_t mIndex;
#endif
};
} // namespace
@ -1295,7 +1299,7 @@ void CustomElementReactionsStack::PopAndInvokeElementQueue() {
lastIndex == mReactionsStack.Length() - 1,
"reactions created by InvokeReactions() should be consumed and removed");
mReactionsStack.RemoveElementAt(lastIndex);
mReactionsStack.RemoveLastElement();
mIsElementQueuePushedForCurrentRecursionDepth = false;
}

View File

@ -204,7 +204,7 @@ void ResponsiveImageSelector::SetDefaultSource(const nsAString& aURLString,
int32_t candidates = mCandidates.Length();
if (candidates && (mCandidates[candidates - 1].Type() ==
ResponsiveImageCandidate::eCandidateType_Default)) {
mCandidates.RemoveElementAt(candidates - 1);
mCandidates.RemoveLastElement();
}
mDefaultSourceURL = aURLString;

View File

@ -911,16 +911,15 @@ void nsDOMMutationObserver::EnterMutationHandling() { ++sMutationLevel; }
void nsDOMMutationObserver::LeaveMutationHandling() {
if (sCurrentlyHandlingObservers &&
sCurrentlyHandlingObservers->Length() == sMutationLevel) {
nsTArray<RefPtr<nsDOMMutationObserver>>& obs =
sCurrentlyHandlingObservers->ElementAt(sMutationLevel - 1);
nsTArray<RefPtr<nsDOMMutationObserver>> obs =
sCurrentlyHandlingObservers->PopLastElement();
for (uint32_t i = 0; i < obs.Length(); ++i) {
nsDOMMutationObserver* o = static_cast<nsDOMMutationObserver*>(obs[i]);
if (o->mCurrentMutations.Length() == sMutationLevel) {
// It is already in pending mutations.
o->mCurrentMutations.RemoveElementAt(sMutationLevel - 1);
o->mCurrentMutations.RemoveLastElement();
}
}
sCurrentlyHandlingObservers->RemoveElementAt(sMutationLevel - 1);
}
--sMutationLevel;
}

View File

@ -383,13 +383,7 @@ void nsPlainTextSerializer::PushBool(nsTArray<bool>& aStack, bool aValue) {
}
bool nsPlainTextSerializer::PopBool(nsTArray<bool>& aStack) {
bool returnValue = false;
uint32_t size = aStack.Length();
if (size > 0) {
returnValue = aStack.ElementAt(size - 1);
aStack.RemoveElementAt(size - 1);
}
return returnValue;
return aStack.Length() ? aStack.PopLastElement() : false;
}
bool nsPlainTextSerializer::IsIgnorableRubyAnnotation(

View File

@ -432,7 +432,7 @@ void nsXMLContentSerializer::PopNameSpaceDeclsFor(nsIContent* aOwner) {
if (mNameSpaceStack[index].mOwner != aOwner) {
break;
}
mNameSpaceStack.RemoveElementAt(index);
mNameSpaceStack.RemoveLastElement();
}
}

View File

@ -306,8 +306,7 @@ void AutoChildOpArgs::Add(JSContext* aCx, const InternalRequest& aRequest,
if (aRv.Failed()) {
CleanupChild(pair.request().body(), Delete);
args.requestResponseList().RemoveElementAt(
args.requestResponseList().Length() - 1);
args.requestResponseList().RemoveLastElement();
}
break;

View File

@ -1935,7 +1935,7 @@ static bool ProcessArguments(JSContext* aCx, const Sequence<JS::Value>& aData,
// If there isn't any output but there's already a style, then
// discard the previous style and use the next one instead.
if (output.IsEmpty() && !aStyles.IsEmpty()) {
aStyles.TruncateLength(aStyles.Length() - 1);
aStyles.RemoveLastElement();
}
if (NS_WARN_IF(!FlushOutput(aCx, aSequence, output))) {
@ -2084,9 +2084,7 @@ static bool UnstoreGroupName(nsAString& aName,
return false;
}
uint32_t pos = aGroupStack->Length() - 1;
aName = (*aGroupStack)[pos];
aGroupStack->RemoveElementAt(pos);
aName = aGroupStack->PopLastElement();
return true;
}

View File

@ -149,9 +149,8 @@ class EventTargetChainItem {
static void DestroyLast(nsTArray<EventTargetChainItem>& aChain,
EventTargetChainItem* aItem) {
uint32_t lastIndex = aChain.Length() - 1;
MOZ_ASSERT(&aChain[lastIndex] == aItem);
aChain.RemoveElementAt(lastIndex);
MOZ_ASSERT(&aChain.LastElement() == aItem);
aChain.RemoveLastElement();
}
static EventTargetChainItem* GetFirstCanHandleEventTarget(

View File

@ -1389,8 +1389,7 @@ TextControlState::TextControlState(TextControlElement* aOwningElement)
TextControlState* TextControlState::Construct(
TextControlElement* aOwningElement) {
if (sReleasedInstances && !sReleasedInstances->IsEmpty()) {
TextControlState* state = sReleasedInstances->LastElement();
sReleasedInstances->RemoveLastElement();
TextControlState* state = sReleasedInstances->PopLastElement();
state->mTextCtrlElement = aOwningElement;
state->mBoundFrame = nullptr;
state->mSelectionProperties = SelectionProperties();

View File

@ -551,15 +551,13 @@ HTMLContentSink::~HTMLContentSink() {
mNotificationTimer->Cancel();
}
int32_t numContexts = mContextStack.Length();
if (mCurrentContext == mHeadContext && numContexts > 0) {
if (mCurrentContext == mHeadContext && !mContextStack.IsEmpty()) {
// Pop off the second html context if it's not done earlier
mContextStack.RemoveElementAt(--numContexts);
mContextStack.RemoveLastElement();
}
int32_t i;
for (i = 0; i < numContexts; i++) {
for (int32_t i = 0, numContexts = mContextStack.Length(); i < numContexts;
i++) {
SinkContext* sc = mContextStack.ElementAt(i);
if (sc) {
sc->End();
@ -716,11 +714,8 @@ HTMLContentSink::SetParser(nsParserBase* aParser) {
nsresult HTMLContentSink::CloseHTML() {
if (mHeadContext) {
if (mCurrentContext == mHeadContext) {
uint32_t numContexts = mContextStack.Length();
// Pop off the second html context if it's not done earlier
mCurrentContext = mContextStack.ElementAt(--numContexts);
mContextStack.RemoveElementAt(numContexts);
mCurrentContext = mContextStack.PopLastElement();
}
mHeadContext->End();
@ -842,9 +837,7 @@ void HTMLContentSink::CloseHeadContext() {
}
if (!mContextStack.IsEmpty()) {
uint32_t n = mContextStack.Length() - 1;
mCurrentContext = mContextStack.ElementAt(n);
mContextStack.RemoveElementAt(n);
mCurrentContext = mContextStack.PopLastElement();
}
}

View File

@ -12496,11 +12496,8 @@ bool ConnectionPool::ScheduleTransaction(TransactionInfo* aTransactionInfo,
return false;
}
} else {
const uint32_t lastIndex = mIdleThreads.Length() - 1;
dbInfo->mThreadInfo = std::move(mIdleThreads[lastIndex].mThreadInfo);
mIdleThreads.RemoveElementAt(lastIndex);
dbInfo->mThreadInfo =
std::move(mIdleThreads.PopLastElement().mThreadInfo);
AdjustIdleTimer();
}

View File

@ -161,16 +161,12 @@ void AudioNode::DisconnectFromGraph() {
// Disconnect inputs. We don't need them anymore.
while (!mInputNodes.IsEmpty()) {
size_t i = mInputNodes.Length() - 1;
RefPtr<AudioNode> input = mInputNodes[i].mInputNode;
mInputNodes.RemoveElementAt(i);
input->mOutputNodes.RemoveElement(this);
InputNode inputNode = mInputNodes.PopLastElement();
inputNode.mInputNode->mOutputNodes.RemoveElement(this);
}
while (!mOutputNodes.IsEmpty()) {
size_t i = mOutputNodes.Length() - 1;
RefPtr<AudioNode> output = std::move(mOutputNodes[i]);
mOutputNodes.RemoveElementAt(i);
RefPtr<AudioNode> output = mOutputNodes.PopLastElement();
size_t inputIndex = FindIndexOfNode(output->mInputNodes, this);
// It doesn't matter which one we remove, since we're going to remove all
// entries for this node anyway.
@ -180,9 +176,7 @@ void AudioNode::DisconnectFromGraph() {
}
while (!mOutputParams.IsEmpty()) {
size_t i = mOutputParams.Length() - 1;
RefPtr<AudioParam> output = std::move(mOutputParams[i]);
mOutputParams.RemoveElementAt(i);
RefPtr<AudioParam> output = mOutputParams.PopLastElement();
size_t inputIndex = FindIndexOfNode(output->InputNodes(), this);
// It doesn't matter which one we remove, since we're going to remove all
// entries for this node anyway.

View File

@ -143,6 +143,10 @@ class AudioNode : public DOMEventTargetHelper, public nsSupportsWeakReference {
}
struct InputNode final {
InputNode() = default;
InputNode(const InputNode&) = delete;
InputNode(InputNode&&) = default;
~InputNode() {
if (mTrackPort) {
mTrackPort->Destroy();

View File

@ -55,9 +55,7 @@ void AudioParam::DisconnectFromGraphAndDestroyTrack() {
"mRefCnt.stabilizeForDeletion()");
while (!mInputNodes.IsEmpty()) {
uint32_t i = mInputNodes.Length() - 1;
RefPtr<AudioNode> input = mInputNodes[i].mInputNode;
mInputNodes.RemoveElementAt(i);
RefPtr<AudioNode> input = mInputNodes.PopLastElement().mInputNode;
input->RemoveOutputParam(this);
}

View File

@ -781,9 +781,7 @@ nsresult nsNPAPIPluginInstance::PushPopupsEnabledState(bool aEnabled) {
}
nsresult nsNPAPIPluginInstance::PopPopupsEnabledState() {
int32_t last = mPopupStates.Length() - 1;
if (last < 0) {
if (mPopupStates.IsEmpty()) {
// Nothing to pop.
return NS_OK;
}
@ -791,11 +789,7 @@ nsresult nsNPAPIPluginInstance::PopPopupsEnabledState() {
nsCOMPtr<nsPIDOMWindowOuter> window = GetDOMWindow();
if (!window) return NS_ERROR_FAILURE;
PopupBlocker::PopupControlState& oldState = mPopupStates[last];
PopupBlocker::PopPopupControlState(oldState);
mPopupStates.RemoveElementAt(last);
PopupBlocker::PopPopupControlState(mPopupStates.PopLastElement());
return NS_OK;
}

View File

@ -1818,13 +1818,14 @@ void PluginModuleChild::EnteredCall() { mIncallPumpingStack.AppendElement(); }
void PluginModuleChild::ExitedCall() {
NS_ASSERTION(mIncallPumpingStack.Length(), "mismatched entered/exited");
uint32_t len = mIncallPumpingStack.Length();
const IncallFrame& f = mIncallPumpingStack[len - 1];
const IncallFrame& f = mIncallPumpingStack.LastElement();
if (f._spinning)
MessageLoop::current()->SetNestableTasksAllowed(
f._savedNestableTasksAllowed);
mIncallPumpingStack.TruncateLength(len - 1);
// XXX Is RemoveLastElement intentionally called only after calling
// SetNestableTasksAllowed? Otherwise, PopLastElement could be used above.
mIncallPumpingStack.RemoveLastElement();
}
LRESULT CALLBACK PluginModuleChild::CallWindowProcHook(int nCode, WPARAM wParam,

View File

@ -1696,9 +1696,7 @@ void nsWebBrowserPersist::FinishSaveDocumentInternal(nsIURI* aFile,
}
if (mWalkStack.Length() > 0) {
mozilla::UniquePtr<WalkData> toWalk;
mWalkStack.LastElement().swap(toWalk);
mWalkStack.TruncateLength(mWalkStack.Length() - 1);
mozilla::UniquePtr<WalkData> toWalk = mWalkStack.PopLastElement();
// Bounce this off the event loop to avoid stack overflow.
typedef StoreCopyPassByRRef<decltype(toWalk)> WalkStorage;
auto saveMethod = &nsWebBrowserPersist::SaveDocumentDeferred;

View File

@ -49,9 +49,7 @@ struct StorageWithTArray {
return false;
}
uint32_t index = aStorage.Length() - 1;
aEntry = aStorage.ElementAt(index);
aStorage.RemoveElementAt(index);
aEntry = aStorage.PopLastElement();
return true;
}

View File

@ -1358,7 +1358,7 @@ bool RuntimeService::ScheduleWorker(WorkerPrivate& aWorkerPrivate) {
{
MutexAutoLock lock(mMutex);
if (!mIdleThreadArray.IsEmpty()) {
thread = mIdleThreadArray.PopLastElement().mThread;
thread = std::move(mIdleThreadArray.PopLastElement().mThread);
}
}

View File

@ -798,14 +798,12 @@ nsresult nsXMLContentSink::PushContent(nsIContent* aContent) {
}
void nsXMLContentSink::PopContent() {
int32_t count = mContentStack.Length();
if (count == 0) {
if (mContentStack.IsEmpty()) {
NS_WARNING("Popping empty stack");
return;
}
mContentStack.RemoveElementAt(count - 1);
mContentStack.RemoveLastElement();
}
bool nsXMLContentSink::HaveNotifiedForCurrentContent() const {

View File

@ -44,9 +44,7 @@ class txStack : private nsTArray<void*> {
void* object = nullptr;
NS_ASSERTION(!isEmpty(), "popping from empty stack");
if (!isEmpty()) {
const uint32_t count = Length() - 1;
object = ElementAt(count);
RemoveElementAt(count);
object = PopLastElement();
}
return object;
}

View File

@ -331,13 +331,8 @@ nsresult txExecutionState::pushBool(bool aBool) {
bool txExecutionState::popBool() {
NS_ASSERTION(mBoolStack.Length(), "popping from empty stack");
uint32_t last = mBoolStack.Length() - 1;
NS_ENSURE_TRUE(last != (uint32_t)-1, false);
bool res = mBoolStack.ElementAt(last);
mBoolStack.RemoveElementAt(last);
return res;
return mBoolStack.IsEmpty() ? false : mBoolStack.PopLastElement();
}
nsresult txExecutionState::pushResultHandler(txAXMLEventHandler* aHandler) {

View File

@ -589,13 +589,11 @@ nsresult txStylesheetCompilerState::pushPtr(void* aPtr, enumStackType aType) {
}
void* txStylesheetCompilerState::popPtr(enumStackType aType) {
uint32_t stacklen = mTypeStack.Length();
if (stacklen == 0) {
if (mTypeStack.IsEmpty()) {
MOZ_CRASH("Attempt to pop when type stack is empty");
}
enumStackType type = mTypeStack.ElementAt(stacklen - 1);
mTypeStack.RemoveElementAt(stacklen - 1);
enumStackType type = mTypeStack.PopLastElement();
void* value = mOtherStack.pop();
#ifdef TX_DEBUG_STACK

View File

@ -207,15 +207,9 @@ void TypeInState::ClearProp(nsAtom* aProp, nsAtom* aAttr) {
* Caller assumes ownership of PropItem and must delete it.
*/
UniquePtr<PropItem> TypeInState::TakeClearProperty() {
size_t count = mClearedArray.Length();
if (!count) {
return nullptr;
}
--count; // indices are zero based
PropItem* propItem = mClearedArray[count];
mClearedArray.RemoveElementAt(count);
return UniquePtr<PropItem>(propItem);
return mClearedArray.Length()
? UniquePtr<PropItem>{mClearedArray.PopLastElement()}
: nullptr;
}
/**
@ -223,14 +217,8 @@ UniquePtr<PropItem> TypeInState::TakeClearProperty() {
* Caller assumes ownership of PropItem and must delete it.
*/
UniquePtr<PropItem> TypeInState::TakeSetProperty() {
size_t count = mSetArray.Length();
if (!count) {
return nullptr;
}
count--; // indices are zero based
PropItem* propItem = mSetArray[count];
mSetArray.RemoveElementAt(count);
return UniquePtr<PropItem>(propItem);
return mSetArray.Length() ? UniquePtr<PropItem>{mSetArray.PopLastElement()}
: nullptr;
}
/**

View File

@ -84,10 +84,7 @@ UniquePtr<uint8_t[]> BufferRecycleBin::GetBuffer(uint32_t aSize) {
return UniquePtr<uint8_t[]>(new (fallible) uint8_t[aSize]);
}
uint32_t last = mRecycledBuffers.Length() - 1;
UniquePtr<uint8_t[]> result = std::move(mRecycledBuffers[last]);
mRecycledBuffers.RemoveElementAt(last);
return result;
return mRecycledBuffers.PopLastElement();
}
void BufferRecycleBin::ClearRecycledBuffers() {

View File

@ -301,12 +301,9 @@ void SortLayersBy3DZOrder(nsTArray<Layer*>& aLayers) {
// and remove edges from it.
do {
if (!noIncoming.IsEmpty()) {
uint32_t last = noIncoming.Length() - 1;
Layer* layer = noIncoming.ElementAt(last);
Layer* layer = noIncoming.PopLastElement();
MOZ_ASSERT(layer); // don't let null layer pointers sneak into sortedList
noIncoming.RemoveElementAt(last);
sortedList.AppendElement(layer);
nsTArray<DirectedGraph<Layer*>::Edge> outgoing;

View File

@ -72,11 +72,9 @@ layers::OffsetRange ShmSegmentsWriter::Write(Range<uint8_t> aBytes) {
if (!AllocChunk()) {
// Allocation failed, so roll back to the state at the start of this
// Write() call and abort.
for (size_t i = mSmallAllocs.Length(); currAllocLen < i; i--) {
MOZ_ASSERT(i > 0);
RefCountedShmem& shm = mSmallAllocs.ElementAt(i - 1);
while (mSmallAllocs.Length() > currAllocLen) {
RefCountedShmem shm = mSmallAllocs.PopLastElement();
RefCountedShm::Dealloc(mShmAllocator, shm);
mSmallAllocs.RemoveElementAt(i - 1);
}
MOZ_ASSERT(mSmallAllocs.Length() == currAllocLen);
return layers::OffsetRange(0, start, 0);

View File

@ -607,11 +607,10 @@ void PresShell::DirtyRootsList::Remove(nsIFrame* aFrame) {
nsIFrame* PresShell::DirtyRootsList::PopShallowestRoot() {
// List is sorted in order of decreasing depth, so there are no deeper
// frames than the last one.
const FrameAndDepth& lastFAD = mList.LastElement();
const FrameAndDepth& lastFAD = mList.PopLastElement();
nsIFrame* frame = lastFAD.mFrame;
// We don't expect frame to change depths.
MOZ_ASSERT(frame->GetDepthInFrameTree() == lastFAD.mDepth);
mList.RemoveLastElement();
return frame;
}

View File

@ -453,7 +453,7 @@ struct MOZ_STACK_CLASS BidiParagraphData {
MOZ_ASSERT(mEmbeddingStack.Length(), "embedding/override underflow");
MOZ_ASSERT(aCh == mEmbeddingStack.LastElement());
AppendPopChar(aCh);
mEmbeddingStack.TruncateLength(mEmbeddingStack.Length() - 1);
mEmbeddingStack.RemoveLastElement();
}
void ClearBidiControls() {

View File

@ -27,12 +27,10 @@ template <size_t ArenaSize, typename ObjectId, size_t ObjectIdCount>
nsPresArena<ArenaSize, ObjectId, ObjectIdCount>::~nsPresArena() {
#if defined(MOZ_HAVE_MEM_CHECKS)
for (FreeList* entry = mFreeLists; entry != ArrayEnd(mFreeLists); ++entry) {
nsTArray<void*>::index_type len;
while ((len = entry->mEntries.Length())) {
void* result = entry->mEntries.ElementAt(len - 1);
entry->mEntries.RemoveElementAt(len - 1);
for (void* result : entry->mEntries) {
MOZ_MAKE_MEM_UNDEFINED(result, entry->mEntrySize);
}
entry->mEntries.Clear();
}
#endif
}

View File

@ -981,10 +981,7 @@ bool ServoStyleSet::EnsureUniqueInnerOnCSSSheets() {
});
while (!queue.IsEmpty()) {
uint32_t idx = queue.Length() - 1;
auto* sheet = queue[idx].first;
SheetOwner owner = queue[idx].second;
queue.RemoveElementAt(idx);
auto [sheet, owner] = queue.PopLastElement();
// Only call EnsureUniqueInner for complete sheets. If we do call it on
// incomplete sheets, we'll cause problems when the sheet is actually

View File

@ -1627,7 +1627,7 @@ nsTextFrame* TextFrameIterator::Next() {
mCurrentPosition -= mCurrentFrame->GetPosition();
if (mCurrentFrame->GetContent()->IsSVGElement(nsGkAtoms::textPath)) {
// Pop off the <textPath> frame if this is a <textPath>.
mTextPathFrames.TruncateLength(mTextPathFrames.Length() - 1);
mTextPathFrames.RemoveLastElement();
}
// Pop off the current baseline.
PopBaseline();
@ -1674,7 +1674,7 @@ void TextFrameIterator::PushBaseline(nsIFrame* aNextFrame) {
void TextFrameIterator::PopBaseline() {
NS_ASSERTION(!mBaselines.IsEmpty(), "popped too many baselines");
mBaselines.TruncateLength(mBaselines.Length() - 1);
mBaselines.RemoveLastElement();
}
// -----------------------------------------------------------------------------

View File

@ -570,7 +570,7 @@ void nsTableFrame::InsertCol(nsTableColFrame& aColFrame, int32_t aColIndex) {
nsTableColType lastColType = lastCol->GetColType();
if (eColAnonymousCell == lastColType) {
// remove the col from the cache
mColFrames.RemoveElementAt(numCacheCols - 1);
mColFrames.RemoveLastElement();
// remove the col from the synthetic col group
nsTableColGroupFrame* lastColGroup =
(nsTableColGroupFrame*)mColGroups.LastChild();

View File

@ -36,8 +36,7 @@ nsresult CacheIndexIterator::GetNextHash(SHA1Sum::Hash* aHash) {
return mStatus;
}
memcpy(aHash, mRecords[mRecords.Length() - 1]->mHash, sizeof(SHA1Sum::Hash));
mRecords.RemoveLastElement();
memcpy(aHash, mRecords.PopLastElement()->mHash, sizeof(SHA1Sum::Hash));
return NS_OK;
}

View File

@ -9035,10 +9035,10 @@ void nsHttpChannel::PushRedirectAsyncFunc(nsContinueRedirectionFunc func) {
}
void nsHttpChannel::PopRedirectAsyncFunc(nsContinueRedirectionFunc func) {
MOZ_ASSERT(func == mRedirectFuncStack[mRedirectFuncStack.Length() - 1],
MOZ_ASSERT(func == mRedirectFuncStack.LastElement(),
"Trying to pop wrong method from redirect async stack!");
mRedirectFuncStack.TruncateLength(mRedirectFuncStack.Length() - 1);
mRedirectFuncStack.RemoveLastElement();
}
//-----------------------------------------------------------------------------

View File

@ -728,7 +728,7 @@ HttpConnectionBase* nsHttpConnectionMgr::FindCoalescableConnectionByHashKey(
listOfWeakConns->Elements()[j] =
listOfWeakConns->Elements()[listLen - 1];
}
listOfWeakConns->RemoveElementAt(listLen - 1);
listOfWeakConns->RemoveLastElement();
MOZ_ASSERT(listOfWeakConns->Length() == listLen - 1);
listLen--;
continue; // without adjusting iterator

View File

@ -96,9 +96,7 @@ nsCommandLine::RemoveArguments(int32_t aStart, int32_t aEnd) {
NS_ENSURE_ARG_MIN(aStart, 0);
NS_ENSURE_ARG_MAX(uint32_t(aEnd) + 1, mArgs.Length());
for (int32_t i = aEnd; i >= aStart; --i) {
mArgs.RemoveElementAt(i);
}
mArgs.RemoveElementsAt(mArgs.begin() + aStart, mArgs.begin() + aEnd + 1);
return NS_OK;
}

View File

@ -990,12 +990,10 @@ nsresult PendingLookup::LookupNext() {
// If a url is in blocklist we should call PendingLookup::OnComplete directly.
MOZ_ASSERT(mBlocklistCount == 0);
int index = mAnylistSpecs.Length() - 1;
nsCString spec;
if (index >= 0) {
if (!mAnylistSpecs.IsEmpty()) {
// Check the source URI only.
spec = mAnylistSpecs[index];
mAnylistSpecs.RemoveElementAt(index);
spec = mAnylistSpecs.PopLastElement();
RefPtr<PendingDBLookup> lookup(new PendingDBLookup(this));
// We don't need to check whitelist if the file is not a binary file.
@ -1004,11 +1002,9 @@ nsresult PendingLookup::LookupNext() {
return lookup->LookupSpec(spec, type);
}
index = mBlocklistSpecs.Length() - 1;
if (index >= 0) {
if (!mBlocklistSpecs.IsEmpty()) {
// Check the referrer and redirect chain.
spec = mBlocklistSpecs[index];
mBlocklistSpecs.RemoveElementAt(index);
spec = mBlocklistSpecs.PopLastElement();
RefPtr<PendingDBLookup> lookup(new PendingDBLookup(this));
return lookup->LookupSpec(spec, LookupType::BlocklistOnly);
}
@ -1024,11 +1020,9 @@ nsresult PendingLookup::LookupNext() {
MOZ_ASSERT_IF(!mIsBinaryFile, mAllowlistSpecs.Length() == 0);
// Only binary signatures remain.
index = mAllowlistSpecs.Length() - 1;
if (index >= 0) {
spec = mAllowlistSpecs[index];
if (!mAllowlistSpecs.IsEmpty()) {
spec = mAllowlistSpecs.PopLastElement();
LOG(("PendingLookup::LookupNext: checking %s on allowlist", spec.get()));
mAllowlistSpecs.RemoveElementAt(index);
RefPtr<PendingDBLookup> lookup(new PendingDBLookup(this));
return lookup->LookupSpec(spec, LookupType::AllowlistOnly);
}

View File

@ -540,7 +540,7 @@ nsresult nsUrlClassifierPrefixSet::WritePrefixes(
totalDeltas += deltaLength;
indexStarts.AppendElement(totalDeltas);
}
indexStarts.RemoveElementAt(indexSize); // we don't use the last element
indexStarts.RemoveLastElement(); // we don't use the last element
MOZ_ASSERT(indexStarts.Length() == indexSize);
}

View File

@ -1421,8 +1421,7 @@ void nsCocoaUtils::ResolveMediaCapturePromises(bool aGranted, PromiseArray& aPro
// Remove each promise from the list and resolve it.
while (aPromiseList->Length() > 0) {
RefPtr<Promise> promise = aPromiseList->LastElement();
aPromiseList->RemoveLastElement();
RefPtr<Promise> promise = aPromiseList->PopLastElement();
// Resolve on main thread
nsCOMPtr<nsIRunnable> runnable(NS_NewRunnableFunction(

View File

@ -969,19 +969,16 @@ void WindowSurfaceWayland::CacheImageSurface(
WindowImageSurface surf = WindowImageSurface(mImageSurface, aRegion);
if (mDelayedImageCommits.Length()) {
int lastSurf = mDelayedImageCommits.Length() - 1;
if (surf.OverlapsSurface(mDelayedImageCommits[lastSurf])) {
auto lastSurf = mDelayedImageCommits.PopLastElement();
if (surf.OverlapsSurface(lastSurf)) {
#ifdef MOZ_LOGGING
{
gfx::IntRect size = mDelayedImageCommits[lastSurf]
.GetUpdateRegion()
->GetBounds()
.ToUnknownRect();
gfx::IntRect size =
lastSurf.GetUpdateRegion()->GetBounds().ToUnknownRect();
LOGWAYLAND((" removing [ %d, %d] -> [%d x %d]\n", size.x, size.y,
size.width, size.height));
}
#endif
mDelayedImageCommits.RemoveElementAt(lastSurf);
}
}

View File

@ -2046,9 +2046,8 @@ void nsMemoryReporterManager::EndProcessReport(uint32_t aGeneration,
while (s->mNumProcessesRunning < s->mConcurrencyLimit &&
!s->mChildrenPending.IsEmpty()) {
// Pop last element from s->mChildrenPending
RefPtr<MemoryReportingProcess> nextChild;
nextChild.swap(s->mChildrenPending.LastElement());
s->mChildrenPending.TruncateLength(s->mChildrenPending.Length() - 1);
const RefPtr<MemoryReportingProcess> nextChild =
s->mChildrenPending.PopLastElement();
// Start report (if the child is still alive).
if (StartChildReport(nextChild, s)) {
++s->mNumProcessesRunning;

View File

@ -189,12 +189,13 @@ class ExpirationTrackerImpl {
MOZ_ASSERT(generation.Length() > index && generation[index] == aObj,
"Object is lying about its index");
// Move the last object to fill the hole created by removing aObj
uint32_t last = generation.Length() - 1;
T* lastObj = generation[last];
generation[index] = lastObj;
T* lastObj = generation.PopLastElement();
// XXX It looks weird that index might point to the element that was just
// removed. Is that really correct?
if (index < generation.Length()) {
generation[index] = lastObj;
}
lastObj->GetExpirationState()->mIndexInGeneration = index;
generation.RemoveElementAt(last);
MOZ_ASSERT(generation.Length() == last);
state->mGeneration = nsExpirationState::NOT_TRACKED;
// We do not check whether we need to stop the timer here. The timer
// will check that itself next time it fires. Checking here would not

View File

@ -93,11 +93,15 @@ class nsTPriorityQueue {
*/
T Pop() {
MOZ_ASSERT(!mElements.IsEmpty(), "Empty queue");
T pop = mElements[0];
T pop = std::move(mElements[0]);
if (mElements.Length() == 1) {
mElements.Clear();
return pop;
}
// Move last to front
mElements[0] = mElements[mElements.Length() - 1];
mElements.TruncateLength(mElements.Length() - 1);
mElements[0] = mElements.PopLastElement();
// Sift down
size_type i = 0;