Bug 1593260 - Don't use remove_if for sweeping GCVector as the predicate can modify the elements r=anba

Differential Revision: https://phabricator.services.mozilla.com/D51786

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jon Coppeard 2019-11-05 15:42:19 +00:00
Родитель 9a7b0768dc
Коммит 72de7c7261
1 изменённых файлов: 13 добавлений и 6 удалений

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

@ -148,13 +148,20 @@ class GCVector {
bool needsSweep() const { return !this->empty(); }
void sweep() {
// This is similar to Vector::eraseIf, but passes a non-const pointer to
// needsSweep().
T* newEnd = std::remove_if(
begin(), end(), [](T& t) { return GCPolicy<T>::needsSweep(&t); });
T* src = begin();
T* dst = begin();
while (src != end()) {
if (!GCPolicy<T>::needsSweep(src)) {
if (src != dst) {
*dst = std::move(*src);
}
dst++;
}
src++;
}
MOZ_ASSERT(newEnd <= end());
shrinkBy(end() - newEnd);
MOZ_ASSERT(dst <= end());
shrinkBy(end() - dst);
}
};