Commit 0c8f54fd authored by cbruni's avatar cbruni Committed by Commit bot

[elements] move MoveElements to abstract superclass

BUG=

Review URL: https://codereview.chromium.org/1841713002

Cr-Commit-Position: refs/heads/master@{#35109}
parent c1caa08f
......@@ -1603,13 +1603,6 @@ class FastElementsAccessor
receiver, backing_store, args, unshift_size, AT_START);
}
static void MoveElements(Isolate* isolate, Handle<JSArray> receiver,
Handle<FixedArrayBase> backing_store, int dst_index,
int src_index, int len, int hole_start,
int hole_end) {
UNREACHABLE();
}
static Handle<JSArray> SliceImpl(Handle<JSObject> receiver,
uint32_t start, uint32_t end) {
Isolate* isolate = receiver->GetIsolate();
......@@ -1700,6 +1693,36 @@ class FastElementsAccessor
return Just(true);
}
static void MoveElements(Isolate* isolate, Handle<JSArray> receiver,
Handle<FixedArrayBase> backing_store, int dst_index,
int src_index, int len, int hole_start,
int hole_end) {
Heap* heap = isolate->heap();
Handle<BackingStore> dst_elms = Handle<BackingStore>::cast(backing_store);
if (heap->CanMoveObjectStart(*dst_elms) && dst_index == 0) {
// Update all the copies of this backing_store handle.
*dst_elms.location() =
BackingStore::cast(heap->LeftTrimFixedArray(*dst_elms, src_index));
receiver->set_elements(*dst_elms);
// Adjust the hole offset as the array has been shrunk.
hole_end -= src_index;
DCHECK_LE(hole_start, backing_store->length());
DCHECK_LE(hole_end, backing_store->length());
} else if (len != 0) {
if (IsFastDoubleElementsKind(KindTraits::Kind)) {
MemMove(dst_elms->data_start() + dst_index,
dst_elms->data_start() + src_index, len * kDoubleSize);
} else {
DisallowHeapAllocation no_gc;
heap->MoveElements(FixedArray::cast(*dst_elms), dst_index, src_index,
len);
}
}
if (hole_start != hole_end) {
dst_elms->FillWithHoles(hole_start, hole_end);
}
}
private:
// SpliceShrinkStep might modify the backing_store.
static void SpliceShrinkStep(Isolate* isolate, Handle<JSArray> receiver,
......@@ -1858,29 +1881,6 @@ class FastSmiOrObjectElementsAccessor
return backing_store->get(index);
}
static void MoveElements(Isolate* isolate, Handle<JSArray> receiver,
Handle<FixedArrayBase> backing_store, int dst_index,
int src_index, int len, int hole_start,
int hole_end) {
Heap* heap = isolate->heap();
Handle<FixedArray> dst_elms = Handle<FixedArray>::cast(backing_store);
if (heap->CanMoveObjectStart(*dst_elms) && dst_index == 0) {
// Update all the copies of this backing_store handle.
*dst_elms.location() =
FixedArray::cast(heap->LeftTrimFixedArray(*dst_elms, src_index));
receiver->set_elements(*dst_elms);
// Adjust the hole offset as the array has been shrunk.
hole_end -= src_index;
DCHECK_LE(hole_start, backing_store->length());
DCHECK_LE(hole_end, backing_store->length());
} else if (len != 0) {
DisallowHeapAllocation no_gc;
heap->MoveElements(*dst_elms, dst_index, src_index, len);
}
if (hole_start != hole_end) {
dst_elms->FillWithHoles(hole_start, hole_end);
}
}
// NOTE: this method violates the handlified function signature convention:
// raw pointer parameters in the function that allocates.
......@@ -2012,31 +2012,6 @@ class FastDoubleElementsAccessor
FixedDoubleArray::cast(backing_store)->set(entry, value->Number());
}
static void MoveElements(Isolate* isolate, Handle<JSArray> receiver,
Handle<FixedArrayBase> backing_store, int dst_index,
int src_index, int len, int hole_start,
int hole_end) {
Heap* heap = isolate->heap();
Handle<FixedDoubleArray> dst_elms =
Handle<FixedDoubleArray>::cast(backing_store);
if (heap->CanMoveObjectStart(*dst_elms) && dst_index == 0) {
// Update all the copies of this backing_store handle.
*dst_elms.location() = FixedDoubleArray::cast(
heap->LeftTrimFixedArray(*dst_elms, src_index));
receiver->set_elements(*dst_elms);
// Adjust the hole offset as the array has been shrunk.
hole_end -= src_index;
DCHECK_LE(hole_start, backing_store->length());
DCHECK_LE(hole_end, backing_store->length());
} else if (len != 0) {
MemMove(dst_elms->data_start() + dst_index,
dst_elms->data_start() + src_index, len * kDoubleSize);
}
if (hole_start != hole_end) {
dst_elms->FillWithHoles(hole_start, hole_end);
}
}
static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
FixedArrayBase* to, ElementsKind from_kind,
uint32_t to_start, int packed_size,
......
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