JSArray::shiftCountWith* could be more efficient
authormhahnenberg@apple.com <mhahnenberg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 May 2014 18:07:48 +0000 (18:07 +0000)
committermhahnenberg@apple.com <mhahnenberg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 May 2014 18:07:48 +0000 (18:07 +0000)
commitd687cb42efbd85df13fbb05c9d21afdeb62831ce
tree9381469f59d7850e0530065025bb4cca764b8bcc
parent0a4f9e4be481c8b135a99b8ba98674a98785f060
JSArray::shiftCountWith* could be more efficient
https://bugs.webkit.org/show_bug.cgi?id=133011

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:
Our current implementations of shiftCountWithAnyIndexingType and shiftCountWithArrayStorage
are scared of the presence of any holes in the array. We can mitigate this somewhat by enabling
them to correctly handle holes, thus avoiding the slowest of slow paths in most cases.

* runtime/ArrayStorage.h:
(JSC::ArrayStorage::indexingHeader):
(JSC::ArrayStorage::length):
(JSC::ArrayStorage::hasHoles):
* runtime/IndexingHeader.h:
(JSC::IndexingHeader::publicLength):
(JSC::IndexingHeader::from):
* runtime/JSArray.cpp:
(JSC::JSArray::shiftCountWithArrayStorage):
(JSC::JSArray::shiftCountWithAnyIndexingType):
(JSC::JSArray::unshiftCountWithArrayStorage):
* runtime/JSArray.h:
(JSC::JSArray::shiftCountForShift):
(JSC::JSArray::shiftCountForSplice):
(JSC::JSArray::shiftCount):
* runtime/Structure.cpp:
(JSC::Structure::holesRequireSpecialBehavior):
* runtime/Structure.h:

LayoutTests:
Added a performance regression test which tests the contiguous shift case. We're ~85% faster
on this microbenchmark with this patch.

Also added a bunch of tests for each permutation of contiguous/array storage with no holes, holes,
and holes that require special behavior (e.g. indexed properties in the prototype chain).

* js/array-storage-splice-holes-expected.txt: Added.
* js/array-storage-splice-holes-require-special-behavior-expected.txt: Added.
* js/array-storage-splice-holes-require-special-behavior.html: Added.
* js/array-storage-splice-holes.html: Added.
* js/array-storage-splice-no-holes-expected.txt: Added.
* js/array-storage-splice-no-holes.html: Added.
* js/contiguous-splice-holes-expected.txt: Added.
* js/contiguous-splice-holes-require-special-behavior-expected.txt: Added.
* js/contiguous-splice-holes-require-special-behavior.html: Added.
* js/contiguous-splice-holes.html: Added.
* js/contiguous-splice-no-holes-expected.txt: Added.
* js/contiguous-splice-no-holes.html: Added.
* js/regress/array-splice-contiguous-expected.txt: Added.
* js/regress/array-splice-contiguous.html: Added.
* js/regress/script-tests/array-splice-contiguous.js: Added.
(foo):
* js/script-tests/array-storage-splice-holes-require-special-behavior.js: Added.
* js/script-tests/array-storage-splice-holes.js: Added.
* js/script-tests/array-storage-splice-no-holes.js: Added.
* js/script-tests/contiguous-splice-holes-require-special-behavior.js: Added.
* js/script-tests/contiguous-splice-holes.js: Added.
* js/script-tests/contiguous-splice-no-holes.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169121 268f45cc-cd09-0410-ab3c-d52691b4dbfc
29 files changed:
LayoutTests/ChangeLog
LayoutTests/js/array-storage-splice-holes-expected.txt [new file with mode: 0644]
LayoutTests/js/array-storage-splice-holes-require-special-behavior-expected.txt [new file with mode: 0644]
LayoutTests/js/array-storage-splice-holes-require-special-behavior.html [new file with mode: 0644]
LayoutTests/js/array-storage-splice-holes.html [new file with mode: 0644]
LayoutTests/js/array-storage-splice-no-holes-expected.txt [new file with mode: 0644]
LayoutTests/js/array-storage-splice-no-holes.html [new file with mode: 0644]
LayoutTests/js/contiguous-splice-holes-expected.txt [new file with mode: 0644]
LayoutTests/js/contiguous-splice-holes-require-special-behavior-expected.txt [new file with mode: 0644]
LayoutTests/js/contiguous-splice-holes-require-special-behavior.html [new file with mode: 0644]
LayoutTests/js/contiguous-splice-holes.html [new file with mode: 0644]
LayoutTests/js/contiguous-splice-no-holes-expected.txt [new file with mode: 0644]
LayoutTests/js/contiguous-splice-no-holes.html [new file with mode: 0644]
LayoutTests/js/regress/array-splice-contiguous-expected.txt [new file with mode: 0644]
LayoutTests/js/regress/array-splice-contiguous.html [new file with mode: 0644]
LayoutTests/js/regress/script-tests/array-splice-contiguous.js [new file with mode: 0644]
LayoutTests/js/script-tests/array-storage-splice-holes-require-special-behavior.js [new file with mode: 0644]
LayoutTests/js/script-tests/array-storage-splice-holes.js [new file with mode: 0644]
LayoutTests/js/script-tests/array-storage-splice-no-holes.js [new file with mode: 0644]
LayoutTests/js/script-tests/contiguous-splice-holes-require-special-behavior.js [new file with mode: 0644]
LayoutTests/js/script-tests/contiguous-splice-holes.js [new file with mode: 0644]
LayoutTests/js/script-tests/contiguous-splice-no-holes.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/ArrayStorage.h
Source/JavaScriptCore/runtime/IndexingHeader.h
Source/JavaScriptCore/runtime/JSArray.cpp
Source/JavaScriptCore/runtime/JSArray.h
Source/JavaScriptCore/runtime/Structure.cpp
Source/JavaScriptCore/runtime/Structure.h