Skip to content

Commit ca8134c

Browse files
camillobruniCommit bot
authored andcommitted
Adding ElementsAccessor::Pop
Moving FastElements path to ElementsAccessor. BUG= Review URL: https://codereview.chromium.org/1325483002 Cr-Commit-Position: refs/heads/master@{#30477}
1 parent 8ff59e8 commit ca8134c

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

src/builtins.cc

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ inline bool GetSloppyArgumentsLength(Isolate* isolate, Handle<JSObject> object,
218218
}
219219

220220

221-
bool PrototypeHasNoElements(PrototypeIterator* iter) {
221+
inline bool PrototypeHasNoElements(PrototypeIterator* iter) {
222222
DisallowHeapAllocation no_gc;
223223
for (; !iter->IsAtEnd(); iter->Advance()) {
224224
if (iter->GetCurrent()->IsJSProxy()) return false;
@@ -396,13 +396,18 @@ BUILTIN(ArrayPop) {
396396
return CallJsIntrinsic(isolate, isolate->array_pop(), args);
397397
}
398398

399-
uint32_t new_length = len - 1;
400-
Handle<Object> element;
401-
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
402-
isolate, element, Object::GetElement(isolate, array, new_length));
403-
404-
JSArray::SetLength(array, new_length);
405-
return *element;
399+
Handle<Object> result;
400+
if (IsJSArrayFastElementMovingAllowed(isolate, JSArray::cast(*receiver))) {
401+
// Fast Elements Path
402+
result = array->GetElementsAccessor()->Pop(array, elms_obj);
403+
} else {
404+
// Use Slow Lookup otherwise
405+
uint32_t new_length = len - 1;
406+
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
407+
isolate, result, Object::GetElement(isolate, array, new_length));
408+
JSArray::SetLength(array, new_length);
409+
}
410+
return *result;
406411
}
407412

408413

src/elements-kind.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ inline bool IsHoleyElementsKind(ElementsKind kind) {
158158

159159

160160
inline bool IsFastPackedElementsKind(ElementsKind kind) {
161-
return kind == FAST_SMI_ELEMENTS ||
162-
kind == FAST_DOUBLE_ELEMENTS ||
163-
kind == FAST_ELEMENTS;
161+
return kind == FAST_SMI_ELEMENTS || kind == FAST_DOUBLE_ELEMENTS ||
162+
kind == FAST_ELEMENTS;
164163
}
165164

166165

src/elements.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,16 @@ class ElementsAccessorBase : public ElementsAccessor {
639639
return Handle<JSArray>();
640640
}
641641

642+
virtual Handle<Object> Pop(Handle<JSArray> receiver,
643+
Handle<FixedArrayBase> backing_store) final {
644+
return ElementsAccessorSubclass::PopImpl(receiver, backing_store);
645+
}
646+
647+
static Handle<Object> PopImpl(Handle<JSArray> receiver,
648+
Handle<FixedArrayBase> backing_store) {
649+
UNREACHABLE();
650+
return Handle<Object>();
651+
}
642652

643653
virtual void SetLength(Handle<JSArray> array, uint32_t length) final {
644654
ElementsAccessorSubclass::SetLengthImpl(array, length,
@@ -1219,6 +1229,21 @@ class FastElementsAccessor
12191229
#endif
12201230
}
12211231

1232+
static Handle<Object> PopImpl(Handle<JSArray> receiver,
1233+
Handle<FixedArrayBase> backing_store) {
1234+
uint32_t new_length =
1235+
static_cast<uint32_t>(Smi::cast(receiver->length())->value()) - 1;
1236+
Handle<Object> result =
1237+
FastElementsAccessorSubclass::GetImpl(backing_store, new_length);
1238+
FastElementsAccessorSubclass::SetLengthImpl(receiver, new_length,
1239+
backing_store);
1240+
1241+
if (IsHoleyElementsKind(KindTraits::Kind) && result->IsTheHole()) {
1242+
result = receiver->GetIsolate()->factory()->undefined_value();
1243+
}
1244+
return result;
1245+
}
1246+
12221247
static uint32_t PushImpl(Handle<JSArray> receiver,
12231248
Handle<FixedArrayBase> backing_store,
12241249
Object** objects, uint32_t push_size,

src/elements.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ class ElementsAccessor {
145145
uint32_t start, uint32_t delete_count,
146146
Arguments args, uint32_t add_count) = 0;
147147

148+
virtual Handle<Object> Pop(Handle<JSArray> receiver,
149+
Handle<FixedArrayBase> backing_store) = 0;
150+
148151
protected:
149152
friend class LookupIterator;
150153

0 commit comments

Comments
 (0)