Repository navigation
Commit 7b9df2f
committed
[JSC] Implement
https://bugs.webkit.org/show_bug.cgi?id=294503
Reviewed by Yusuke Suzuki.
This patch implements `Array.prototype.flat` in C++.
The new fast path for `Array#flat` first calculates the length
of the resulting array using O(n) `calculateFlattenedLength`,
then directly sets values into the butterfly buffer of the
resulting array using O(n) `fastFlatIntoBuffer`.
TipOfTree Patched
array-prototype-flat-depth-1-string 395.8826+-4.5561 ^ 147.9479+-3.7062 ^ definitely 2.6758x faster
array-prototype-flat-large-nested 111.9910+-4.9277 ^ 30.5805+-0.2314 ^ definitely 3.6622x faster
array-prototype-flat-sparse-array 198.6802+-2.0652 ^ 133.4569+-3.7686 ^ definitely 1.4887x faster
array-prototype-flat-small-arrays 9.0792+-0.4023 ^ 4.8345+-0.1067 ^ definitely 1.8780x faster
array-prototype-flat-depth-1-double 600.7011+-40.1338 ^ 105.1259+-1.4612 ^ definitely 5.7141x faster
array-prototype-flat-depth-1-int32 447.6045+-6.5491 ^ 106.2142+-7.6386 ^ definitely 4.2142x faster
array-prototype-flat-depth-infinity 524.9275+-4.1636 ^ 141.2842+-5.6371 ^ definitely 3.7154x faster
array-prototype-flat-depth-2 522.6723+-2.1402 ^ 118.4029+-5.5013 ^ definitely 4.4144x faster
array-prototype-flat-huge-arrays 43.4337+-3.9484 ^ 10.1096+-0.1294 ^ definitely 4.2963x faster
array-prototype-flat-depth-1-mixed 450.7441+-18.1260 ^ 136.2629+-0.7525 ^ definitely 3.3079x faster
array-prototype-flat-depth-3 526.4249+-2.3837 ^ 124.7195+-4.6807 ^ definitely 4.2209x faster
* JSTests/microbenchmarks/array-prototype-flat-depth-1-double.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-1-int32.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-1-mixed.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-1-string.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-2.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-3.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-infinity.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-huge-arrays.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-large-nested.js: Added.
(shouldBe):
(createLargeNestedArray):
* JSTests/microbenchmarks/array-prototype-flat-small-arrays.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-sparse-array.js: Added.
(shouldBe):
* JSTests/stress/array-prototype-flat-hole.js: Added.
(shouldBe):
* JSTests/stress/array-prototype-flat-nested-proxy-array.js: Added.
(shouldBe):
(const.handler.has):
* Source/JavaScriptCore/builtins/ArrayPrototype.js:
(flat): Deleted.
* Source/JavaScriptCore/runtime/ArrayPrototype.cpp:
(JSC::ArrayPrototype::finishCreation):
(JSC::flatIntoArray):
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/CommonIdentifiers.h:
* Source/JavaScriptCore/runtime/JSArray.cpp:
(JSC::calculateFlattenedLength):
(JSC::fastFlatIntoBuffer):
(JSC::JSArray::fastFlat):
* Source/JavaScriptCore/runtime/JSArray.h:
Canonical link: https://commits.webkit.org/298127@mainArray.prototype.flat in C++1 parent 96d4563 commit 7b9df2f
18 files changed
Lines changed: 575 additions & 20 deletions
File tree
- JSTests
- microbenchmarks
- stress
- Source/JavaScriptCore
- builtins
- runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
0 commit comments