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

Unified Diff: src/builtins.cc

Issue 1322803002: Adding ElementsAccessor::Unshift (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2015-08-28_elements_accessor_pop
Patch Set: space Created 5 years, 4 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 890885267a98c46a519e249b148a806b611944df..5ae9a5e94f5107c35a53861d63ae43b23ab38d46 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -472,51 +472,17 @@ BUILTIN(ArrayUnshift) {
}
Handle<JSArray> array = Handle<JSArray>::cast(receiver);
DCHECK(!array->map()->is_observed());
- if (!array->HasFastSmiOrObjectElements()) {
- return CallJsIntrinsic(isolate, isolate->array_unshift(), args);
- }
- int len = Smi::cast(array->length())->value();
int to_add = args.length() - 1;
- int new_length = len + to_add;
// Currently fixed arrays cannot grow too big, so
// we should never hit this case.
- DCHECK(to_add <= (Smi::kMaxValue - len));
+ DCHECK(to_add <= (Smi::kMaxValue - Smi::cast(array->length())->value()));
- if (to_add > 0 && JSArray::WouldChangeReadOnlyLength(array, len + to_add)) {
+ if (to_add > 0 && JSArray::HasReadOnlyLength(array)) {
return CallJsIntrinsic(isolate, isolate->array_unshift(), args);
}
- Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
-
- 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);
-
- ElementsKind kind = array->GetElementsKind();
- ElementsAccessor* accessor = array->GetElementsAccessor();
- accessor->CopyElements(
- elms, 0, kind, new_elms, to_add,
- ElementsAccessor::kCopyToEndAndInitializeToHole);
-
- elms = new_elms;
- array->set_elements(*elms);
- } else {
- DisallowHeapAllocation no_gc;
- Heap* heap = isolate->heap();
- heap->MoveElements(*elms, to_add, 0, len);
- }
-
- // Add the provided values.
- DisallowHeapAllocation no_gc;
- WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
- for (int i = 0; i < to_add; i++) {
- elms->set(i, args[i + 1], mode);
- }
-
- // Set the length.
- array->set_length(Smi::FromInt(new_length));
+ ElementsAccessor* accessor = array->GetElementsAccessor();
+ int new_length = accessor->Unshift(array, elms_obj, &args, to_add);
return Smi::FromInt(new_length);
}
« 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