Bug 1951338: Add fast path for packed elements in willBeSparseElements r=jandem

I originally intended to reset the NON_PACKED flag in this code if there were no holes, but after a closer look, I realized that we exit early from the loop once we've seen enough non-holes, but resetting the flag would require us to examine every element.

Differential Revision: https://phabricator.services.mozilla.com/D241534
This commit is contained in:
Iain Ireland
2025-03-14 20:33:20 +00:00
parent 3d2e59c22e
commit 0a8be1129a

View File

@@ -545,9 +545,13 @@ bool NativeObject::willBeSparseElements(uint32_t requiredCapacity,
return true; return true;
} }
uint32_t len = getDenseInitializedLength(); uint32_t initLen = getDenseInitializedLength();
if (denseElementsArePacked()) {
return minimalDenseCount > initLen;
}
const Value* elems = getDenseElements(); const Value* elems = getDenseElements();
for (uint32_t i = 0; i < len; i++) { for (uint32_t i = 0; i < initLen; i++) {
if (!elems[i].isMagic(JS_ELEMENTS_HOLE) && !--minimalDenseCount) { if (!elems[i].isMagic(JS_ELEMENTS_HOLE) && !--minimalDenseCount) {
return false; return false;
} }