Bug 1642989 - Use RemoveLastElements instead of RemoveElementsAt where possible. r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D78049
This commit is contained in:
Simon Giesecke 2020-06-08 08:50:15 +00:00
parent f5561f73b7
commit ebbc7ae838
16 changed files with 38 additions and 41 deletions

View File

@ -2361,7 +2361,7 @@ void DocAccessible::PutChildrenBack(nsTArray<RefPtr<Accessible>>* aChildren,
}
}
aChildren->RemoveElementsAt(aStartIdx, aChildren->Length() - aStartIdx);
aChildren->RemoveLastElements(aChildren->Length() - aStartIdx);
}
bool DocAccessible::MoveChild(Accessible* aChild, Accessible* aNewParent,

View File

@ -1806,18 +1806,20 @@ void HyperTextAccessible::Shutdown() {
}
bool HyperTextAccessible::RemoveChild(Accessible* aAccessible) {
int32_t childIndex = aAccessible->IndexInParent();
int32_t count = mOffsets.Length() - childIndex;
if (count > 0) mOffsets.RemoveElementsAt(childIndex, count);
const int32_t childIndex = aAccessible->IndexInParent();
if (childIndex < static_cast<int64_t>(mOffsets.Length())) {
mOffsets.RemoveLastElements(mOffsets.Length() -
aAccessible->IndexInParent());
}
return AccessibleWrap::RemoveChild(aAccessible);
}
bool HyperTextAccessible::InsertChildAt(uint32_t aIndex, Accessible* aChild) {
int32_t count = mOffsets.Length() - aIndex;
if (count > 0) {
mOffsets.RemoveElementsAt(aIndex, count);
if (aIndex < mOffsets.Length()) {
mOffsets.RemoveLastElements(mOffsets.Length() - aIndex);
}
return AccessibleWrap::InsertChildAt(aIndex, aChild);
}

View File

@ -3536,7 +3536,8 @@ void HTMLMediaElement::UpdateOutputTrackSources() {
}
// Then work out the differences.
mediaTracksToAdd.RemoveElementsAt(
mediaTracksToAdd.RemoveLastElements(
mediaTracksToAdd.end() -
std::remove_if(mediaTracksToAdd.begin(), mediaTracksToAdd.end(),
[this, &trackSourcesToRemove](const auto& track) {
const bool remove =
@ -3545,8 +3546,7 @@ void HTMLMediaElement::UpdateOutputTrackSources() {
trackSourcesToRemove.RemoveElement(track->GetId());
}
return remove;
}),
mediaTracksToAdd.end());
}));
// First remove stale track sources.
for (const auto& id : trackSourcesToRemove) {

View File

@ -12752,12 +12752,12 @@ void ConnectionPool::NoteClosedDatabase(DatabaseInfo* aDatabaseInfo) {
// See if we need to fire any complete callbacks now that the database is
// finished.
mCompleteCallbacks.RemoveElementsAt(
mCompleteCallbacks.RemoveLastElements(
mCompleteCallbacks.end() -
std::remove_if(mCompleteCallbacks.begin(), mCompleteCallbacks.end(),
[&me = *this](const auto& completeCallback) {
return me.MaybeFireCallback(completeCallback.get());
}),
mCompleteCallbacks.end());
}));
// If that was the last database and we're supposed to be shutting down then
// we are finished.
@ -20826,14 +20826,14 @@ nsresult FactoryOp::SendVersionChangeMessages(
// We don't want to wait forever if we were not able to send the
// message.
mMaybeBlockedDatabases.RemoveElementsAt(
mMaybeBlockedDatabases.RemoveLastElements(
mMaybeBlockedDatabases.end() -
std::remove_if(mMaybeBlockedDatabases.begin(),
mMaybeBlockedDatabases.end(),
[aOldVersion, &aNewVersion](auto& maybeBlockedDatabase) {
return !maybeBlockedDatabase->SendVersionChange(
aOldVersion, aNewVersion);
}),
mMaybeBlockedDatabases.end());
}));
return NS_OK;
} // namespace indexedDB

View File

@ -646,13 +646,13 @@ void IDBTransaction::AbortInternal(const nsresult aAbortCode,
return static_cast<uint64_t>(objectStoreId);
});
mObjectStores.RemoveElementsAt(
mObjectStores.RemoveLastElements(
mObjectStores.end() -
std::remove_if(mObjectStores.begin(), mObjectStores.end(),
[&validIds](const auto& objectStore) {
return !validIds.Contains(
uint64_t(objectStore->Id()));
}),
mObjectStores.end());
}));
std::copy_if(std::make_move_iterator(mDeletedObjectStores.begin()),
std::make_move_iterator(mDeletedObjectStores.end()),

View File

@ -1442,10 +1442,9 @@ void MediaRecorder::Start(const Optional<uint32_t>& aTimeslice,
if (mStream) {
mStream->GetTracks(tracks);
}
tracks.RemoveElementsAt(
std::remove_if(tracks.begin(), tracks.end(),
[](const auto& t) { return t->Ended(); }),
tracks.end());
tracks.RemoveLastElements(
tracks.end() - std::remove_if(tracks.begin(), tracks.end(),
[](const auto& t) { return t->Ended(); }));
// 5. If the value of recorders state attribute is not inactive, throw an
// InvalidStateError DOMException and abort these steps.

View File

@ -479,7 +479,7 @@ class MediaSegmentBase : public MediaSegment {
}
// At this point `i` is already advanced due to last check in the loop.
if (i < mChunks.Length()) {
mChunks.RemoveElementsAt(i, mChunks.Length() - i);
mChunks.RemoveLastElements(mChunks.Length() - i);
}
MOZ_ASSERT(mChunks.Capacity() >= DEFAULT_SEGMENT_CAPACITY,
"Capacity must be retained after removing chunks");

View File

@ -165,7 +165,7 @@ class VideoOutput : public DirectMediaTrackListener {
// there might be old frames lingering. We'll find the current one and
// re-send that.
DropPastFrames();
mFrames.RemoveElementsAt(1, mFrames.Length() - 1);
mFrames.RemoveLastElements(mFrames.Length() - 1);
SendFrames();
mFrames.ClearAndRetainStorage();
}

View File

@ -1177,7 +1177,7 @@ bool OpusState::ReconstructOpusGranulepos(void) {
// Encoders SHOULD NOT produce streams like this, but we'll handle
// it for them anyway.
gp = last_gp;
mUnstamped.RemoveElementsAt(i + 1, mUnstamped.Length() - (i + 1));
mUnstamped.RemoveLastElements(mUnstamped.Length() - (i + 1));
packet->e_o_s = 1;
}
}

View File

@ -480,8 +480,8 @@ void AudioNodeTrack::UpMixDownMixChunk(const AudioBlock* aChunk,
}
} else {
// Drop the remaining aOutputChannels
aOutputChannels.RemoveElementsAt(
aOutputChannelCount, aOutputChannels.Length() - aOutputChannelCount);
aOutputChannels.RemoveLastElements(aOutputChannels.Length() -
aOutputChannelCount);
}
}
}

View File

@ -162,7 +162,7 @@ void SpeechSynthesis::Cancel() {
if (!mSpeechQueue.IsEmpty() && HasSpeakingTask()) {
// Remove all queued utterances except for current one, we will remove it
// in OnEnd
mSpeechQueue.RemoveElementsAt(1, mSpeechQueue.Length() - 1);
mSpeechQueue.RemoveLastElements(mSpeechQueue.Length() - 1);
} else {
mSpeechQueue.Clear();
}

View File

@ -407,8 +407,7 @@ void TiledTextureImage::Resize(const gfx::IntSize& aSize) {
}
// Prune any unused tiles at the end of the store.
unsigned int length = mImages.Length();
for (; i < length; i++) mImages.RemoveLastElement();
mImages.RemoveLastElements(mImages.Length() - i);
// Reset tile-store properties.
mRows = rows;

View File

@ -250,7 +250,7 @@ nsresult SourceBuffer::Compact() {
"Compacted chunk has slack space");
// Remove the redundant chunks.
mChunks.RemoveElementsAt(1, mChunks.Length() - 1);
mChunks.RemoveLastElements(mChunks.Length() - 1);
mChunks.Compact();
return NS_OK;

View File

@ -519,7 +519,7 @@ static void ClampColorStops(nsTArray<ColorStop>& aStops) {
InterpolateColorStop(aStops[i - 1], aStops[i],
/* aPosition = */ 1, aStops[i - 1].mColor);
// Remove all the elements whose position is greater than 1.
aStops.RemoveElementsAt(i + 1, aStops.Length() - (i + 1));
aStops.RemoveLastElements(aStops.Length() - (i + 1));
}
if (aStops[i - 1].mPosition <= 0 && aStops[i].mPosition > 0) {
// Add a point to position 0.

View File

@ -412,7 +412,8 @@ void CycleCollectedJSContext::CleanupIDBTransactions(uint32_t aRecursionDepth) {
nsTArray<PendingIDBTransactionData> localQueue =
std::move(mPendingIDBTransactions);
localQueue.RemoveElementsAt(
localQueue.RemoveLastElements(
localQueue.end() -
std::remove_if(localQueue.begin(), localQueue.end(),
[aRecursionDepth](PendingIDBTransactionData& data) {
if (data.mRecursionDepth != aRecursionDepth) {
@ -426,8 +427,7 @@ void CycleCollectedJSContext::CleanupIDBTransactions(uint32_t aRecursionDepth) {
}
return true;
}),
localQueue.end());
}));
// If mPendingIDBTransactions has events in it now, they were added from
// something we called, so they belong at the end of the queue.

View File

@ -674,11 +674,8 @@ void TimerThread::RemoveLeadingCanceledTimersInternal() {
}
// Finally, remove the canceled timers from the back of the
// nsTArray. Note, since std::pop_heap() uses iterators
// we must convert to nsTArray indices and number of
// elements here.
mTimers.RemoveElementsAt(sortedEnd - mTimers.begin(),
mTimers.end() - sortedEnd);
// nsTArray.
mTimers.RemoveLastElements(mTimers.end() - sortedEnd);
}
void TimerThread::RemoveFirstTimerInternal() {