From c536a48bdff1096d459ed949a73fe236a0996ee4 Mon Sep 17 00:00:00 2001 From: Paul Bone Date: Thu, 26 Apr 2018 11:43:46 +1000 Subject: [PATCH] Bug 1407143 (Part 2) - Refactor sweepEntry() for readability r=sfink --HG-- extra : rebase_source : 9af47c96c3bfe35d6610244d5b45f4b102865078 --- js/src/vm/ArrayBufferObject.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/src/vm/ArrayBufferObject.cpp b/js/src/vm/ArrayBufferObject.cpp index 5d8979958e77..96aeb9100701 100644 --- a/js/src/vm/ArrayBufferObject.cpp +++ b/js/src/vm/ArrayBufferObject.cpp @@ -1578,10 +1578,15 @@ InnerViewTable::sweepEntry(JSObject** pkey, ViewVector& views) return true; MOZ_ASSERT(!views.empty()); - for (size_t i = 0; i < views.length(); i++) { + size_t i = 0; + while (i < views.length()) { if (IsAboutToBeFinalizedUnbarriered(&views[i])) { - views[i--] = views.back(); + // If the current element is garbage then remove it from the + // vector by moving the last one into its place. + views[i] = views.back(); views.popBack(); + } else { + i++; } }