Skip to content

Commit 066747e

Browse files
verwaestCommit bot
authored andcommitted
Make sure that NormalizeElements and ShouldConvertToFastElements are based on the same values
BUG=v8:4518 LOG=n Review URL: https://codereview.chromium.org/1472293002 Cr-Commit-Position: refs/heads/master@{#32265}
1 parent 3d004ee commit 066747e

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/elements.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,13 +1227,18 @@ class FastElementsAccessor
12271227
}
12281228
int num_used = 0;
12291229
for (int i = 0; i < backing_store->length(); ++i) {
1230-
if (!backing_store->is_the_hole(i)) ++num_used;
1231-
// Bail out early if more than 1/4 is used.
1232-
if (4 * num_used > backing_store->length()) break;
1233-
}
1234-
if (4 * num_used <= backing_store->length()) {
1235-
JSObject::NormalizeElements(obj);
1230+
if (!backing_store->is_the_hole(i)) {
1231+
++num_used;
1232+
// Bail out if a number dictionary wouldn't be able to save at least
1233+
// 75% space.
1234+
if (4 * SeededNumberDictionary::ComputeCapacity(num_used) *
1235+
SeededNumberDictionary::kEntrySize >
1236+
backing_store->length()) {
1237+
return;
1238+
}
1239+
}
12361240
}
1241+
JSObject::NormalizeElements(obj);
12371242
}
12381243
}
12391244

src/objects.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14646,6 +14646,8 @@ static bool ShouldConvertToFastElements(JSObject* object,
1464614646

1464714647
uint32_t dictionary_size = static_cast<uint32_t>(dictionary->Capacity()) *
1464814648
SeededNumberDictionary::kEntrySize;
14649+
14650+
// Turn fast if the dictionary only saves 50% space.
1464914651
return 2 * dictionary_size >= *new_capacity;
1465014652
}
1465114653

0 commit comments

Comments
 (0)