Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: src/builtins.cc

Issue 1317053006: Adding ElementsAccessor::Shift (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2015-09-01_array_builtin_cleanup
Patch Set: Only use range checks in builtins Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/elements.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index a84d15015c4e3aa01ea5f7cb2cf780b42ad80249..461ba84d7c8ef89d0dd5a9f49a49d8705904112c 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -195,14 +195,6 @@ inline bool ClampedToInteger(Object* object, int* out) {
}
-void MoveDoubleElements(FixedDoubleArray* dst, int dst_index,
- FixedDoubleArray* src, int src_index, int len) {
- if (len == 0) return;
- MemMove(dst->data_start() + dst_index, src->data_start() + src_index,
- len * kDoubleSize);
-}
-
-
inline bool GetSloppyArgumentsLength(Isolate* isolate, Handle<JSObject> object,
int* out) {
Map* arguments_map =
@@ -432,30 +424,7 @@ BUILTIN(ArrayShift) {
return CallJsIntrinsic(isolate, isolate->array_shift(), args);
}
- // Get first element
- Handle<Object> first;
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, first,
- Object::GetElement(isolate, array, 0));
-
- if (heap->CanMoveObjectStart(*elms_obj)) {
- array->set_elements(heap->LeftTrimFixedArray(*elms_obj, 1));
- } else {
- // Shift the elements.
- if (elms_obj->IsFixedArray()) {
- Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
- DisallowHeapAllocation no_gc;
- heap->MoveElements(*elms, 0, 1, len - 1);
- elms->set(len - 1, heap->the_hole_value());
- } else {
- Handle<FixedDoubleArray> elms = Handle<FixedDoubleArray>::cast(elms_obj);
- MoveDoubleElements(*elms, 0, *elms, 1, len - 1);
- elms->set_the_hole(len - 1);
- }
- }
-
- // Set the length.
- array->set_length(Smi::FromInt(len - 1));
-
+ Handle<Object> first = array->GetElementsAccessor()->Shift(array, elms_obj);
return *first;
}
@@ -472,6 +441,9 @@ BUILTIN(ArrayUnshift) {
Handle<JSArray> array = Handle<JSArray>::cast(receiver);
DCHECK(!array->map()->is_observed());
int to_add = args.length() - 1;
+ if (to_add == 0) {
+ return array->length();
+ }
// Currently fixed arrays cannot grow too big, so
// we should never hit this case.
DCHECK(to_add <= (Smi::kMaxValue - Smi::cast(array->length())->value()));
@@ -553,6 +525,12 @@ BUILTIN(ArraySlice) {
uint32_t actual_end =
(relative_end < 0) ? Max(len + relative_end, 0) : Min(relative_end, len);
+ if (actual_end <= actual_start) {
+ Handle<JSArray> result_array =
+ isolate->factory()->NewJSArray(GetInitialFastElementsKind(), 0, 0);
+ return *result_array;
+ }
+
ElementsAccessor* accessor = object->GetElementsAccessor();
if (is_sloppy_arguments &&
!accessor->IsPacked(object, elms_obj, actual_start, actual_end)) {
« no previous file with comments | « no previous file | src/elements.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698