Commit 34700869 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[array] Properly handle COW arrays in Array.p.reverse fast-path

Instead of using the slow-path for COW arrays, we now properly copy
them and use the fast-path.

R=jgruber@chromium.org

Change-Id: Iebbad5f761d97c5400c457877571c7930269d52f
Reviewed-on: https://chromium-review.googlesource.com/1188130
Commit-Queue: Simon Zünd <szuend@google.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55384}
parent 57c8c85b
...@@ -143,14 +143,25 @@ module array { ...@@ -143,14 +143,25 @@ module array {
return object; return object;
} }
macro EnsureWriteableFastElements(array: JSArray) {
const elements: FixedArrayBase = array.elements;
if (elements.map != kCOWMap) return;
// There are no COW *_DOUBLE_ELEMENTS arrays, so we are allowed to always
// extract FixedArrays and don't have to worry about FixedDoubleArrays.
assert(IsFastSmiOrTaggedElementsKind(array.map.elements_kind));
const length: Smi = array.length_fast;
array.elements = ExtractFixedArray(
unsafe_cast<FixedArray>(elements), 0, length, length, kFixedArrays);
}
macro TryFastPackedArrayReverse(receiver: Object) labels Slow { macro TryFastPackedArrayReverse(receiver: Object) labels Slow {
const array: JSArray = cast<JSArray>(receiver) otherwise Slow; const array: JSArray = cast<JSArray>(receiver) otherwise Slow;
const map: Map = array.map; EnsureWriteableFastElements(array);
assert(array.elements.map != kCOWMap);
if (!IsExtensibleMap(map)) goto Slow;
if (array.elements.map == kCOWMap) goto Slow;
const kind: ElementsKind = map.elements_kind; const kind: ElementsKind = array.map.elements_kind;
if (kind == PACKED_SMI_ELEMENTS) { if (kind == PACKED_SMI_ELEMENTS) {
FastPackedArrayReverse<FastPackedSmiElements, Smi>( FastPackedArrayReverse<FastPackedSmiElements, Smi>(
array.elements, array.length_fast); array.elements, array.length_fast);
......
...@@ -109,6 +109,8 @@ type FixedBigInt64Array extends FixedTypedArray; ...@@ -109,6 +109,8 @@ type FixedBigInt64Array extends FixedTypedArray;
const kAllFixedArrays: constexpr ExtractFixedArrayFlags generates const kAllFixedArrays: constexpr ExtractFixedArrayFlags generates
'ExtractFixedArrayFlag::kAllFixedArrays'; 'ExtractFixedArrayFlag::kAllFixedArrays';
const kFixedArrays: constexpr ExtractFixedArrayFlags generates
'ExtractFixedArrayFlag::kFixedArrays';
const kFixedCOWArrayMapRootIndex: constexpr RootListIndex generates const kFixedCOWArrayMapRootIndex: constexpr RootListIndex generates
'Heap::kFixedCOWArrayMapRootIndex'; 'Heap::kFixedCOWArrayMapRootIndex';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment