Backed out 3 changesets (bug 1643289, bug 1642949) for causing failure at test_headless_screenshot.html. CLOSED TREE

Backed out changeset 98c420f73380 (bug 1643289)
Backed out changeset 9447ea8910aa (bug 1643289)
Backed out changeset 0c827da9d847 (bug 1642949)
This commit is contained in:
Butkovits Atila 2020-06-10 10:07:23 +03:00
parent 7473e73dbd
commit e3dce68834
49 changed files with 214 additions and 125 deletions

View File

@ -241,23 +241,19 @@ 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.RemoveLastElement();
mStack.RemoveElementAt(mIndex);
}
private:
nsTArray<RefPtr<Element>>& mStack;
#ifdef DEBUG
uint32_t mIndex;
#endif
};
} // namespace
@ -1299,7 +1295,7 @@ void CustomElementReactionsStack::PopAndInvokeElementQueue() {
lastIndex == mReactionsStack.Length() - 1,
"reactions created by InvokeReactions() should be consumed and removed");
mReactionsStack.RemoveLastElement();
mReactionsStack.RemoveElementAt(lastIndex);
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.RemoveLastElement();
mCandidates.RemoveElementAt(candidates - 1);
}
mDefaultSourceURL = aURLString;

View File

@ -911,15 +911,16 @@ void nsDOMMutationObserver::EnterMutationHandling() { ++sMutationLevel; }
void nsDOMMutationObserver::LeaveMutationHandling() {
if (sCurrentlyHandlingObservers &&
sCurrentlyHandlingObservers->Length() == sMutationLevel) {
nsTArray<RefPtr<nsDOMMutationObserver>> obs =
sCurrentlyHandlingObservers->PopLastElement();
nsTArray<RefPtr<nsDOMMutationObserver>>& obs =
sCurrentlyHandlingObservers->ElementAt(sMutationLevel - 1);
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.RemoveLastElement();
o->mCurrentMutations.RemoveElementAt(sMutationLevel - 1);
}
}
sCurrentlyHandlingObservers->RemoveElementAt(sMutationLevel - 1);
}
--sMutationLevel;
}

View File

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

View File

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

View File

@ -306,7 +306,8 @@ void AutoChildOpArgs::Add(JSContext* aCx, const InternalRequest& aRequest,
if (aRv.Failed()) {
CleanupChild(pair.request().body(), Delete);
args.requestResponseList().RemoveLastElement();
args.requestResponseList().RemoveElementAt(
args.requestResponseList().Length() - 1);
}
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.RemoveLastElement();
aStyles.TruncateLength(aStyles.Length() - 1);
}
if (NS_WARN_IF(!FlushOutput(aCx, aSequence, output))) {
@ -2084,7 +2084,9 @@ static bool UnstoreGroupName(nsAString& aName,
return false;
}
aName = aGroupStack->PopLastElement();
uint32_t pos = aGroupStack->Length() - 1;
aName = (*aGroupStack)[pos];
aGroupStack->RemoveElementAt(pos);
return true;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -43,11 +43,11 @@ RefPtr<MediaDataDecoder::DecodePromise> DummyMediaDataDecoder::Decode(
}
// Frames come out in DTS order but we need to output them in PTS order.
mReorderQueue.Push(std::move(data));
mReorderQueue.Push(data);
if (mReorderQueue.Length() > mMaxRefFrames) {
return DecodePromise::CreateAndResolve(DecodedData{mReorderQueue.Pop()},
__func__);
return DecodePromise::CreateAndResolve(
DecodedData{mReorderQueue.Pop().get()}, __func__);
}
return DecodePromise::CreateAndResolve(DecodedData(), __func__);
}
@ -55,7 +55,7 @@ RefPtr<MediaDataDecoder::DecodePromise> DummyMediaDataDecoder::Decode(
RefPtr<MediaDataDecoder::DecodePromise> DummyMediaDataDecoder::Drain() {
DecodedData samples;
while (!mReorderQueue.IsEmpty()) {
samples.AppendElement(mReorderQueue.Pop());
samples.AppendElement(mReorderQueue.Pop().get());
}
return DecodePromise::CreateAndResolve(std::move(samples), __func__);
}

View File

@ -446,7 +446,7 @@ void AppleVTDecoder::OutputFrame(CVPixelBufferRef aImage,
// Frames come out in DTS order but we need to output them
// in composition order.
MonitorAutoLock mon(mMonitor);
mReorderQueue.Push(std::move(data));
mReorderQueue.Push(data);
MaybeResolveBufferedFrames();
LOG("%llu decoded frames queued",

View File

@ -161,12 +161,16 @@ void AudioNode::DisconnectFromGraph() {
// Disconnect inputs. We don't need them anymore.
while (!mInputNodes.IsEmpty()) {
InputNode inputNode = mInputNodes.PopLastElement();
inputNode.mInputNode->mOutputNodes.RemoveElement(this);
size_t i = mInputNodes.Length() - 1;
RefPtr<AudioNode> input = mInputNodes[i].mInputNode;
mInputNodes.RemoveElementAt(i);
input->mOutputNodes.RemoveElement(this);
}
while (!mOutputNodes.IsEmpty()) {
RefPtr<AudioNode> output = mOutputNodes.PopLastElement();
size_t i = mOutputNodes.Length() - 1;
RefPtr<AudioNode> output = std::move(mOutputNodes[i]);
mOutputNodes.RemoveElementAt(i);
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.
@ -176,7 +180,9 @@ void AudioNode::DisconnectFromGraph() {
}
while (!mOutputParams.IsEmpty()) {
RefPtr<AudioParam> output = mOutputParams.PopLastElement();
size_t i = mOutputParams.Length() - 1;
RefPtr<AudioParam> output = std::move(mOutputParams[i]);
mOutputParams.RemoveElementAt(i);
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,10 +143,6 @@ 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,7 +55,9 @@ void AudioParam::DisconnectFromGraphAndDestroyTrack() {
"mRefCnt.stabilizeForDeletion()");
while (!mInputNodes.IsEmpty()) {
RefPtr<AudioNode> input = mInputNodes.PopLastElement().mInputNode;
uint32_t i = mInputNodes.Length() - 1;
RefPtr<AudioNode> input = mInputNodes[i].mInputNode;
mInputNodes.RemoveElementAt(i);
input->RemoveOutputParam(this);
}

View File

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

View File

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

View File

@ -185,7 +185,7 @@ nsresult SMILTimeContainer::SetParent(SMILTimeContainer* aParent) {
return rv;
}
void SMILTimeContainer::AddMilestone(
bool SMILTimeContainer::AddMilestone(
const SMILMilestone& aMilestone,
mozilla::dom::SVGAnimationElement& aElement) {
// We record the milestone time and store it along with the element but this
@ -193,7 +193,7 @@ void SMILTimeContainer::AddMilestone(
// between samples). If this happens, then we may do an unecessary sample
// but that's pretty cheap.
MOZ_ASSERT(!mHoldingEntries);
mMilestoneEntries.Push(MilestoneEntry(aMilestone, aElement));
return mMilestoneEntries.Push(MilestoneEntry(aMilestone, aElement));
}
void SMILTimeContainer::ClearMilestones() {

View File

@ -168,8 +168,9 @@ class SMILTimeContainer {
* @param aMilestone The milestone to register in container time.
* @param aElement The timebase element that needs a sample at
* aMilestone.
* @return true if the element was successfully added, false otherwise.
*/
void AddMilestone(const SMILMilestone& aMilestone,
bool AddMilestone(const SMILMilestone& aMilestone,
mozilla::dom::SVGAnimationElement& aElement);
/*

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -331,8 +331,13 @@ 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);
return mBoolStack.IsEmpty() ? false : mBoolStack.PopLastElement();
bool res = mBoolStack.ElementAt(last);
mBoolStack.RemoveElementAt(last);
return res;
}
nsresult txExecutionState::pushResultHandler(txAXMLEventHandler* aHandler) {

View File

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

View File

@ -207,9 +207,15 @@ void TypeInState::ClearProp(nsAtom* aProp, nsAtom* aAttr) {
* Caller assumes ownership of PropItem and must delete it.
*/
UniquePtr<PropItem> TypeInState::TakeClearProperty() {
return mClearedArray.Length()
? UniquePtr<PropItem>{mClearedArray.PopLastElement()}
: nullptr;
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);
}
/**
@ -217,8 +223,14 @@ UniquePtr<PropItem> TypeInState::TakeClearProperty() {
* Caller assumes ownership of PropItem and must delete it.
*/
UniquePtr<PropItem> TypeInState::TakeSetProperty() {
return mSetArray.Length() ? UniquePtr<PropItem>{mSetArray.PopLastElement()}
: nullptr;
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);
}
/**

View File

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

View File

@ -301,9 +301,12 @@ void SortLayersBy3DZOrder(nsTArray<Layer*>& aLayers) {
// and remove edges from it.
do {
if (!noIncoming.IsEmpty()) {
Layer* layer = noIncoming.PopLastElement();
uint32_t last = noIncoming.Length() - 1;
Layer* layer = noIncoming.ElementAt(last);
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,9 +72,11 @@ 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.
while (mSmallAllocs.Length() > currAllocLen) {
RefCountedShmem shm = mSmallAllocs.PopLastElement();
for (size_t i = mSmallAllocs.Length(); currAllocLen < i; i--) {
MOZ_ASSERT(i > 0);
RefCountedShmem& shm = mSmallAllocs.ElementAt(i - 1);
RefCountedShm::Dealloc(mShmAllocator, shm);
mSmallAllocs.RemoveElementAt(i - 1);
}
MOZ_ASSERT(mSmallAllocs.Length() == currAllocLen);
return layers::OffsetRange(0, start, 0);

View File

@ -607,10 +607,11 @@ 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.PopLastElement();
const FrameAndDepth& lastFAD = mList.LastElement();
nsIFrame* frame = lastFAD.mFrame;
// We don't expect frame to change depths.
MOZ_ASSERT(frame->GetDepthInFrameTree() == lastFAD.mDepth);
mList.RemoveLastElement();
return frame;
}
@ -5258,7 +5259,8 @@ nscolor PresShell::GetDefaultBackgroundColorToDraw() {
BrowsingContext* bc = doc->GetBrowsingContext();
if (bc && bc->IsTop() && !bc->HasOpener() && doc->GetDocumentURI() &&
NS_IsAboutBlank(doc->GetDocumentURI()) &&
doc->PrefersColorScheme(Document::IgnoreRFP::Yes) == StylePrefersColorScheme::Dark) {
doc->PrefersColorScheme(Document::IgnoreRFP::Yes) ==
StylePrefersColorScheme::Dark) {
// Use --in-content-page-background for prefers-color-scheme: dark.
return NS_RGB(0x2A, 0x2A, 0x2E);
}

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.RemoveLastElement();
mEmbeddingStack.TruncateLength(mEmbeddingStack.Length() - 1);
}
void ClearBidiControls() {

View File

@ -27,10 +27,12 @@ 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) {
for (void* result : entry->mEntries) {
nsTArray<void*>::index_type len;
while ((len = entry->mEntries.Length())) {
void* result = entry->mEntries.ElementAt(len - 1);
entry->mEntries.RemoveElementAt(len - 1);
MOZ_MAKE_MEM_UNDEFINED(result, entry->mEntrySize);
}
entry->mEntries.Clear();
}
#endif
}

View File

@ -981,7 +981,10 @@ bool ServoStyleSet::EnsureUniqueInnerOnCSSSheets() {
});
while (!queue.IsEmpty()) {
auto [sheet, owner] = queue.PopLastElement();
uint32_t idx = queue.Length() - 1;
auto* sheet = queue[idx].first;
SheetOwner owner = queue[idx].second;
queue.RemoveElementAt(idx);
// 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.RemoveLastElement();
mTextPathFrames.TruncateLength(mTextPathFrames.Length() - 1);
}
// 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.RemoveLastElement();
mBaselines.TruncateLength(mBaselines.Length() - 1);
}
// -----------------------------------------------------------------------------

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.RemoveLastElement();
mColFrames.RemoveElementAt(numCacheCols - 1);
// remove the col from the synthetic col group
nsTableColGroupFrame* lastColGroup =
(nsTableColGroupFrame*)mColGroups.LastChild();

View File

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

View File

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

View File

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

View File

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

View File

@ -990,10 +990,12 @@ 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 (!mAnylistSpecs.IsEmpty()) {
if (index >= 0) {
// Check the source URI only.
spec = mAnylistSpecs.PopLastElement();
spec = mAnylistSpecs[index];
mAnylistSpecs.RemoveElementAt(index);
RefPtr<PendingDBLookup> lookup(new PendingDBLookup(this));
// We don't need to check whitelist if the file is not a binary file.
@ -1002,9 +1004,11 @@ nsresult PendingLookup::LookupNext() {
return lookup->LookupSpec(spec, type);
}
if (!mBlocklistSpecs.IsEmpty()) {
index = mBlocklistSpecs.Length() - 1;
if (index >= 0) {
// Check the referrer and redirect chain.
spec = mBlocklistSpecs.PopLastElement();
spec = mBlocklistSpecs[index];
mBlocklistSpecs.RemoveElementAt(index);
RefPtr<PendingDBLookup> lookup(new PendingDBLookup(this));
return lookup->LookupSpec(spec, LookupType::BlocklistOnly);
}
@ -1020,9 +1024,11 @@ nsresult PendingLookup::LookupNext() {
MOZ_ASSERT_IF(!mIsBinaryFile, mAllowlistSpecs.Length() == 0);
// Only binary signatures remain.
if (!mAllowlistSpecs.IsEmpty()) {
spec = mAllowlistSpecs.PopLastElement();
index = mAllowlistSpecs.Length() - 1;
if (index >= 0) {
spec = mAllowlistSpecs[index];
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.RemoveLastElement(); // we don't use the last element
indexStarts.RemoveElementAt(indexSize); // we don't use the last element
MOZ_ASSERT(indexStarts.Length() == indexSize);
}

View File

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

View File

@ -969,16 +969,19 @@ void WindowSurfaceWayland::CacheImageSurface(
WindowImageSurface surf = WindowImageSurface(mImageSurface, aRegion);
if (mDelayedImageCommits.Length()) {
auto lastSurf = mDelayedImageCommits.PopLastElement();
if (surf.OverlapsSurface(lastSurf)) {
int lastSurf = mDelayedImageCommits.Length() - 1;
if (surf.OverlapsSurface(mDelayedImageCommits[lastSurf])) {
#ifdef MOZ_LOGGING
{
gfx::IntRect size =
lastSurf.GetUpdateRegion()->GetBounds().ToUnknownRect();
gfx::IntRect size = mDelayedImageCommits[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,8 +2046,9 @@ void nsMemoryReporterManager::EndProcessReport(uint32_t aGeneration,
while (s->mNumProcessesRunning < s->mConcurrencyLimit &&
!s->mChildrenPending.IsEmpty()) {
// Pop last element from s->mChildrenPending
const RefPtr<MemoryReportingProcess> nextChild =
s->mChildrenPending.PopLastElement();
RefPtr<MemoryReportingProcess> nextChild;
nextChild.swap(s->mChildrenPending.LastElement());
s->mChildrenPending.TruncateLength(s->mChildrenPending.Length() - 1);
// Start report (if the child is still alive).
if (StartChildReport(nextChild, s)) {
++s->mNumProcessesRunning;

View File

@ -189,13 +189,12 @@ 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
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;
}
uint32_t last = generation.Length() - 1;
T* lastObj = generation[last];
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

@ -32,8 +32,11 @@ class nsTPriorityQueue {
*/
explicit nsTPriorityQueue(const Compare& aComp) : mCompare(aComp) {}
nsTPriorityQueue(nsTPriorityQueue&&) = default;
nsTPriorityQueue& operator=(nsTPriorityQueue&&) = default;
/**
* Copy constructor
*/
nsTPriorityQueue(const nsTPriorityQueue& aOther)
: mElements(aOther.mElements), mCompare(aOther.mCompare) {}
/**
* @return True if the queue is empty or false otherwise.
@ -62,8 +65,11 @@ class nsTPriorityQueue {
* @param aElement The element to add
* @return true on success, false on out of memory.
*/
void Push(T&& aElement) {
mElements.AppendElement(std::move(aElement));
bool Push(const T& aElement) {
T* elem = mElements.AppendElement(aElement);
if (!elem) {
return false; // Out of memory
}
// Sift up
size_type i = mElements.Length() - 1;
@ -72,9 +78,11 @@ class nsTPriorityQueue {
if (mCompare.LessThan(mElements[parent], mElements[i])) {
break;
}
std::swap(mElements[i], mElements[parent]);
Swap(i, parent);
i = parent;
}
return true;
}
/**
@ -85,34 +93,29 @@ class nsTPriorityQueue {
*/
T Pop() {
MOZ_ASSERT(!mElements.IsEmpty(), "Empty queue");
T pop = std::move(mElements[0]);
const size_type newLength = mElements.Length() - 1;
if (newLength == 0) {
mElements.Clear();
return pop;
}
T pop = mElements[0];
// Move last to front
mElements[0] = mElements.PopLastElement();
mElements[0] = mElements[mElements.Length() - 1];
mElements.TruncateLength(mElements.Length() - 1);
// Sift down
size_type i = 0;
while (2 * i + 1 < newLength) {
while (2 * i + 1 < mElements.Length()) {
size_type swap = i;
size_type l_child = 2 * i + 1;
if (mCompare.LessThan(mElements[l_child], mElements[i])) {
swap = l_child;
}
size_type r_child = l_child + 1;
if (r_child < newLength &&
if (r_child < mElements.Length() &&
mCompare.LessThan(mElements[r_child], mElements[swap])) {
swap = r_child;
}
if (swap == i) {
break;
}
std::swap(mElements[i], mElements[swap]);
Swap(i, swap);
i = swap;
}
@ -133,14 +136,17 @@ class nsTPriorityQueue {
*/
const T* Elements() const { return mElements.Elements(); }
nsTPriorityQueue Clone() const {
auto res = nsTPriorityQueue{mCompare};
res.mElements = mElements.Clone();
return res;
protected:
/**
* Swaps the elements at the specified indices.
*/
void Swap(size_type aIndexA, size_type aIndexB) {
T temp = mElements[aIndexA];
mElements[aIndexA] = mElements[aIndexB];
mElements[aIndexB] = temp;
}
protected:
nsTArray<T> mElements;
CopyableTArray<T> mElements;
Compare mCompare; // Comparator object
};

View File

@ -13,7 +13,7 @@ template <class T, class Compare>
void CheckPopSequence(const nsTPriorityQueue<T, Compare>& aQueue,
const T* aExpectedSequence,
const uint32_t aSequenceLength) {
nsTPriorityQueue<T, Compare> copy = aQueue.Clone();
nsTPriorityQueue<T, Compare> copy(aQueue);
for (uint32_t i = 0; i < aSequenceLength; i++) {
EXPECT_FALSE(copy.IsEmpty());
@ -52,7 +52,7 @@ TEST(PriorityQueue, Main)
// copy ctor is tested by using CheckPopSequence, but check default assignment
// operator
nsTPriorityQueue<int> queue2;
queue2 = queue.Clone();
queue2 = queue;
CheckPopSequence(queue2, expected, sizeof(expected) / sizeof(expected[0]));
queue.Clear();