Commit bf47bfd1 authored by Z Duong Nguyen-Huu's avatar Z Duong Nguyen-Huu Committed by Commit Bot

Refactor holey and packed elements-kind check

Bug: v8:6831
Change-Id: Idbfc2ddb46e258eee2ef23528531b666a532d72c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1599775Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#61328}
parent 175ff6f3
......@@ -199,22 +199,19 @@ inline bool IsHoleyFrozenOrSealedElementsKind(ElementsKind kind) {
}
inline bool IsHoleyElementsKind(ElementsKind kind) {
return kind == HOLEY_SMI_ELEMENTS || kind == HOLEY_DOUBLE_ELEMENTS ||
kind == HOLEY_ELEMENTS;
return kind % 2 == 1 && kind <= HOLEY_DOUBLE_ELEMENTS;
}
inline bool IsHoleyElementsKindForRead(ElementsKind kind) {
return IsHoleyElementsKind(kind) || IsHoleyFrozenOrSealedElementsKind(kind);
return kind % 2 == 1 && kind <= HOLEY_FROZEN_ELEMENTS;
}
inline bool IsHoleyOrDictionaryElementsKind(ElementsKind kind) {
return IsHoleyElementsKindForRead(kind) || kind == DICTIONARY_ELEMENTS;
}
inline bool IsFastPackedElementsKind(ElementsKind kind) {
return kind == PACKED_SMI_ELEMENTS || kind == PACKED_DOUBLE_ELEMENTS ||
kind == PACKED_ELEMENTS;
return kind % 2 == 0 && kind <= PACKED_DOUBLE_ELEMENTS;
}
......
......@@ -58,6 +58,41 @@ bool EQUALS(Isolate* isolate, T left, Handle<M> right) {
return EQUALS(isolate, handle(left, isolate), right);
}
bool ElementsKindIsHoleyElementsKindForRead(ElementsKind kind) {
switch (kind) {
case ElementsKind::HOLEY_SMI_ELEMENTS:
case ElementsKind::HOLEY_ELEMENTS:
case ElementsKind::HOLEY_DOUBLE_ELEMENTS:
case ElementsKind::HOLEY_SEALED_ELEMENTS:
case ElementsKind::HOLEY_FROZEN_ELEMENTS:
return true;
default:
return false;
}
}
bool ElementsKindIsHoleyElementsKind(ElementsKind kind) {
switch (kind) {
case ElementsKind::HOLEY_SMI_ELEMENTS:
case ElementsKind::HOLEY_ELEMENTS:
case ElementsKind::HOLEY_DOUBLE_ELEMENTS:
return true;
default:
return false;
}
}
bool ElementsKindIsFastPackedElementsKind(ElementsKind kind) {
switch (kind) {
case ElementsKind::PACKED_SMI_ELEMENTS:
case ElementsKind::PACKED_ELEMENTS:
case ElementsKind::PACKED_DOUBLE_ELEMENTS:
return true;
default:
return false;
}
}
} // namespace
......@@ -488,6 +523,29 @@ TEST(JSArrayAddingElementsGeneralizingiFastDoubleElements) {
CHECK_EQ(array->map(), *previous_map);
}
TEST(IsHoleyElementsKindForRead) {
for (int i = 0; i <= ElementsKind::LAST_ELEMENTS_KIND; i++) {
ElementsKind kind = static_cast<ElementsKind>(i);
CHECK_EQ(ElementsKindIsHoleyElementsKindForRead(kind),
IsHoleyElementsKindForRead(kind));
}
}
TEST(IsHoleyElementsKind) {
for (int i = 0; i <= ElementsKind::LAST_ELEMENTS_KIND; i++) {
ElementsKind kind = static_cast<ElementsKind>(i);
CHECK_EQ(ElementsKindIsHoleyElementsKind(kind), IsHoleyElementsKind(kind));
}
}
TEST(IsFastPackedElementsKind) {
for (int i = 0; i <= ElementsKind::LAST_ELEMENTS_KIND; i++) {
ElementsKind kind = static_cast<ElementsKind>(i);
CHECK_EQ(ElementsKindIsFastPackedElementsKind(kind),
IsFastPackedElementsKind(kind));
}
}
} // namespace test_elements_kind
} // namespace internal
} // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment