Adding ElementsAccessor::Pop
authorcbruni <cbruni@chromium.org>
Mon, 31 Aug 2015 15:18:01 +0000 (08:18 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 31 Aug 2015 15:18:08 +0000 (15:18 +0000)
Moving FastElements path to ElementsAccessor.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#30477}

src/builtins.cc
src/elements-kind.h
src/elements.cc
src/elements.h

index a9690a7..37286c6 100644 (file)
@@ -218,7 +218,7 @@ inline bool GetSloppyArgumentsLength(Isolate* isolate, Handle<JSObject> object,
 }
 
 
-bool PrototypeHasNoElements(PrototypeIterator* iter) {
+inline bool PrototypeHasNoElements(PrototypeIterator* iter) {
   DisallowHeapAllocation no_gc;
   for (; !iter->IsAtEnd(); iter->Advance()) {
     if (iter->GetCurrent()->IsJSProxy()) return false;
@@ -396,13 +396,18 @@ BUILTIN(ArrayPop) {
     return CallJsIntrinsic(isolate, isolate->array_pop(), args);
   }
 
-  uint32_t new_length = len - 1;
-  Handle<Object> element;
-  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
-      isolate, element, Object::GetElement(isolate, array, new_length));
-
-  JSArray::SetLength(array, new_length);
-  return *element;
+  Handle<Object> result;
+  if (IsJSArrayFastElementMovingAllowed(isolate, JSArray::cast(*receiver))) {
+    // Fast Elements Path
+    result = array->GetElementsAccessor()->Pop(array, elms_obj);
+  } else {
+    // Use Slow Lookup otherwise
+    uint32_t new_length = len - 1;
+    ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+        isolate, result, Object::GetElement(isolate, array, new_length));
+    JSArray::SetLength(array, new_length);
+  }
+  return *result;
 }
 
 
index 0254a4f..d823409 100644 (file)
@@ -158,9 +158,8 @@ inline bool IsHoleyElementsKind(ElementsKind kind) {
 
 
 inline bool IsFastPackedElementsKind(ElementsKind kind) {
-  return kind == FAST_SMI_ELEMENTS ||
-      kind == FAST_DOUBLE_ELEMENTS ||
-      kind == FAST_ELEMENTS;
+  return kind == FAST_SMI_ELEMENTS || kind == FAST_DOUBLE_ELEMENTS ||
+         kind == FAST_ELEMENTS;
 }
 
 
index d17efaf..2cf64c5 100644 (file)
@@ -639,6 +639,16 @@ class ElementsAccessorBase : public ElementsAccessor {
     return Handle<JSArray>();
   }
 
+  virtual Handle<Object> Pop(Handle<JSArray> receiver,
+                             Handle<FixedArrayBase> backing_store) final {
+    return ElementsAccessorSubclass::PopImpl(receiver, backing_store);
+  }
+
+  static Handle<Object> PopImpl(Handle<JSArray> receiver,
+                                Handle<FixedArrayBase> backing_store) {
+    UNREACHABLE();
+    return Handle<Object>();
+  }
 
   virtual void SetLength(Handle<JSArray> array, uint32_t length) final {
     ElementsAccessorSubclass::SetLengthImpl(array, length,
@@ -1219,6 +1229,21 @@ class FastElementsAccessor
 #endif
   }
 
+  static Handle<Object> PopImpl(Handle<JSArray> receiver,
+                                Handle<FixedArrayBase> backing_store) {
+    uint32_t new_length =
+        static_cast<uint32_t>(Smi::cast(receiver->length())->value()) - 1;
+    Handle<Object> result =
+        FastElementsAccessorSubclass::GetImpl(backing_store, new_length);
+    FastElementsAccessorSubclass::SetLengthImpl(receiver, new_length,
+                                                backing_store);
+
+    if (IsHoleyElementsKind(KindTraits::Kind) && result->IsTheHole()) {
+      result = receiver->GetIsolate()->factory()->undefined_value();
+    }
+    return result;
+  }
+
   static uint32_t PushImpl(Handle<JSArray> receiver,
                            Handle<FixedArrayBase> backing_store,
                            Object** objects, uint32_t push_size,
index f5a9b3e..6022375 100644 (file)
@@ -145,6 +145,9 @@ class ElementsAccessor {
                                  uint32_t start, uint32_t delete_count,
                                  Arguments args, uint32_t add_count) = 0;
 
+  virtual Handle<Object> Pop(Handle<JSArray> receiver,
+                             Handle<FixedArrayBase> backing_store) = 0;
+
  protected:
   friend class LookupIterator;