From c15121fef7f1a08614d46bbd5fbbbf4130360a86 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 17 May 2021 23:13:37 +0100 Subject: [PATCH] LibJS: Make length_setter_generic_storage_threshold a global constant This was a bit hard to find as a local variable - rename it to uppercase LENGTH_SETTER_GENERIC_STORAGE_THRESHOLD and move it to the top (next to SPARSE_ARRAY_HOLE_THRESHOLD) for good visibility. --- Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp b/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp index be63dcc8d5..ff828cb6b8 100644 --- a/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp +++ b/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp @@ -10,7 +10,8 @@ namespace JS { -const u32 SPARSE_ARRAY_HOLE_THRESHOLD = 200; +constexpr const size_t SPARSE_ARRAY_HOLE_THRESHOLD = 200; +constexpr const size_t LENGTH_SETTER_GENERIC_STORAGE_THRESHOLD = 4 * MiB; SimpleIndexedPropertyStorage::SimpleIndexedPropertyStorage(Vector&& initial_values) : m_array_size(initial_values.size()) @@ -313,7 +314,6 @@ void IndexedProperties::append_all(Object* this_object, const IndexedProperties& void IndexedProperties::set_array_like_size(size_t new_size) { - constexpr size_t length_setter_generic_storage_threshold = 4 * MiB; auto current_array_like_size = array_like_size(); // We can't use simple storage for lengths that don't fit in an i32. @@ -321,7 +321,7 @@ void IndexedProperties::set_array_like_size(size_t new_size) // This prevents something like "a = []; a.length = 0x80000000;" from allocating 2G entries. if (m_storage->is_simple_storage() && (new_size > NumericLimits::max() - || (current_array_like_size < length_setter_generic_storage_threshold && new_size > length_setter_generic_storage_threshold))) { + || (current_array_like_size < LENGTH_SETTER_GENERIC_STORAGE_THRESHOLD && new_size > LENGTH_SETTER_GENERIC_STORAGE_THRESHOLD))) { switch_to_generic_storage(); }