Index: src/builtins.cc |
diff --git a/src/builtins.cc b/src/builtins.cc |
index 9e04aaa7cca2447d665c872db882d65f7fe36159..190feb889c94638b298b930693fc3b12d3b04aef 100644 |
--- a/src/builtins.cc |
+++ b/src/builtins.cc |
@@ -85,7 +85,6 @@ void BuiltinArguments<NEEDS_CALLED_FUNCTION>::Verify() { |
} |
#endif |
- |
#define DEF_ARG_TYPE(name, spec) \ |
typedef BuiltinArguments<spec> name##ArgumentsType; |
BUILTIN_LIST_C(DEF_ARG_TYPE) |
@@ -321,7 +320,6 @@ BUILTIN(ArrayPush) { |
if (!maybe_elms_obj.ToHandle(&elms_obj)) { |
return CallJsBuiltin(isolate, "$arrayPush", args); |
} |
- |
Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
int len = Smi::cast(array->length())->value(); |
int to_add = args.length() - 1; |
@@ -330,95 +328,10 @@ BUILTIN(ArrayPush) { |
} |
DCHECK(!array->map()->is_observed()); |
- ElementsKind kind = array->GetElementsKind(); |
- |
- if (IsFastSmiOrObjectElementsKind(kind)) { |
- Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); |
- if (to_add == 0) { |
- return Smi::FromInt(len); |
- } |
- // Currently fixed arrays cannot grow too big, so |
- // we should never hit this case. |
- DCHECK(to_add <= (Smi::kMaxValue - len)); |
- |
- int new_length = len + to_add; |
- |
- if (new_length > elms->length()) { |
- // New backing storage is needed. |
- int capacity = new_length + (new_length >> 1) + 16; |
- Handle<FixedArray> new_elms = |
- isolate->factory()->NewUninitializedFixedArray(capacity); |
- |
- ElementsAccessor* accessor = array->GetElementsAccessor(); |
- accessor->CopyElements( |
- elms_obj, 0, kind, new_elms, 0, |
- ElementsAccessor::kCopyToEndAndInitializeToHole); |
- |
- elms = new_elms; |
- } |
- |
- // Add the provided values. |
- DisallowHeapAllocation no_gc; |
- WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); |
- for (int index = 0; index < to_add; index++) { |
- elms->set(index + len, args[index + 1], mode); |
- } |
- |
- if (*elms != array->elements()) { |
- array->set_elements(*elms); |
- } |
- |
- // Set the length. |
- array->set_length(Smi::FromInt(new_length)); |
- return Smi::FromInt(new_length); |
- } else { |
- int elms_len = elms_obj->length(); |
- if (to_add == 0) { |
- return Smi::FromInt(len); |
- } |
- // Currently fixed arrays cannot grow too big, so |
- // we should never hit this case. |
- DCHECK(to_add <= (Smi::kMaxValue - len)); |
- |
- int new_length = len + to_add; |
- |
- Handle<FixedDoubleArray> new_elms; |
- |
- if (new_length > elms_len) { |
- // New backing storage is needed. |
- int capacity = new_length + (new_length >> 1) + 16; |
- // Create new backing store; since capacity > 0, we can |
- // safely cast to FixedDoubleArray. |
- new_elms = Handle<FixedDoubleArray>::cast( |
- isolate->factory()->NewFixedDoubleArray(capacity)); |
- |
- ElementsAccessor* accessor = array->GetElementsAccessor(); |
- accessor->CopyElements( |
- elms_obj, 0, kind, new_elms, 0, |
- ElementsAccessor::kCopyToEndAndInitializeToHole); |
- |
- } else { |
- // to_add is > 0 and new_length <= elms_len, so elms_obj cannot be the |
- // empty_fixed_array. |
- new_elms = Handle<FixedDoubleArray>::cast(elms_obj); |
- } |
- |
- // Add the provided values. |
- DisallowHeapAllocation no_gc; |
- int index; |
- for (index = 0; index < to_add; index++) { |
- Object* arg = args[index + 1]; |
- new_elms->set(index + len, arg->Number()); |
- } |
- |
- if (*new_elms != array->elements()) { |
- array->set_elements(*new_elms); |
- } |
- |
- // Set the length. |
- array->set_length(Smi::FromInt(new_length)); |
- return Smi::FromInt(new_length); |
- } |
+ ElementsAccessor* accessor = array->GetElementsAccessor(); |
+ int new_length = accessor->Push(array, elms_obj, &args[0], 1, to_add, |
Jakob Kummerow
2015/07/30 11:54:59
If you pass in &args[1] here, you don't need the |
|
+ ElementsAccessor::kDirectionReverse); |
+ return Smi::FromInt(new_length); |
} |
@@ -503,7 +416,6 @@ BUILTIN(ArrayShift) { |
BUILTIN(ArrayUnshift) { |
HandleScope scope(isolate); |
- Heap* heap = isolate->heap(); |
Handle<Object> receiver = args.receiver(); |
MaybeHandle<FixedArrayBase> maybe_elms_obj = |
EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1); |
@@ -545,6 +457,7 @@ BUILTIN(ArrayUnshift) { |
array->set_elements(*elms); |
} else { |
DisallowHeapAllocation no_gc; |
+ Heap* heap = isolate->heap(); |
heap->MoveElements(*elms, to_add, 0, len); |
} |