mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 02:03:06 -05:00
LibJS: Eliminate some (unnecessary) Vector copies
This commit is contained in:
parent
8d9c5a8e70
commit
699e1fdc07
Notes:
sideshowbarker
2024-07-19 02:50:37 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/699e1fdc07e Pull-request: https://github.com/SerenityOS/serenity/pull/3432 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg ✅
4 changed files with 11 additions and 11 deletions
|
@ -123,7 +123,7 @@ bool Console::counter_reset(String label)
|
|||
Vector<String> ConsoleClient::get_trace() const
|
||||
{
|
||||
Vector<String> trace;
|
||||
auto call_stack = m_console.interpreter().call_stack();
|
||||
auto& call_stack = m_console.interpreter().call_stack();
|
||||
// -2 to skip the console.trace() call frame
|
||||
for (ssize_t i = call_stack.size() - 2; i >= 0; --i)
|
||||
trace.append(call_stack[i].function_name);
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace JS {
|
|||
Exception::Exception(Value value)
|
||||
: m_value(value)
|
||||
{
|
||||
auto call_stack = interpreter().call_stack();
|
||||
auto& call_stack = interpreter().call_stack();
|
||||
for (ssize_t i = call_stack.size() - 1; i >= 0; --i) {
|
||||
auto function_name = call_stack[i].function_name;
|
||||
if (function_name.is_empty())
|
||||
|
|
|
@ -273,7 +273,7 @@ Optional<ValueAndAttributes> IndexedProperties::get(Object* this_object, u32 ind
|
|||
return result;
|
||||
if (!result.has_value())
|
||||
return {};
|
||||
auto value = result.value();
|
||||
auto& value = result.value();
|
||||
if (value.value.is_accessor()) {
|
||||
ASSERT(this_object);
|
||||
auto& accessor = value.value.as_accessor();
|
||||
|
@ -315,7 +315,7 @@ void IndexedProperties::insert(u32 index, Value value, PropertyAttributes attrib
|
|||
{
|
||||
if (m_storage->is_simple_storage() && (index >= SPARSE_ARRAY_THRESHOLD || attributes != default_attributes || array_like_size() == SPARSE_ARRAY_THRESHOLD))
|
||||
switch_to_generic_storage();
|
||||
m_storage->insert(index, value, attributes);
|
||||
m_storage->insert(index, move(value), attributes);
|
||||
}
|
||||
|
||||
ValueAndAttributes IndexedProperties::take_first(Object* this_object)
|
||||
|
@ -340,7 +340,7 @@ void IndexedProperties::append_all(Object* this_object, const IndexedProperties&
|
|||
switch_to_generic_storage();
|
||||
|
||||
for (auto it = properties.begin(false); it != properties.end(); ++it) {
|
||||
auto element = it.value_and_attributes(this_object, evaluate_accessors);
|
||||
const auto& element = it.value_and_attributes(this_object, evaluate_accessors);
|
||||
if (this_object && this_object->interpreter().exception())
|
||||
return;
|
||||
m_storage->put(m_storage->array_like_size(), element.value, element.attributes);
|
||||
|
@ -357,14 +357,14 @@ void IndexedProperties::set_array_like_size(size_t new_size)
|
|||
Vector<ValueAndAttributes> IndexedProperties::values_unordered() const
|
||||
{
|
||||
if (m_storage->is_simple_storage()) {
|
||||
auto elements = static_cast<const SimpleIndexedPropertyStorage&>(*m_storage).elements();
|
||||
const auto& elements = static_cast<const SimpleIndexedPropertyStorage&>(*m_storage).elements();
|
||||
Vector<ValueAndAttributes> with_attributes;
|
||||
for (auto& value : elements)
|
||||
with_attributes.append({ value, default_attributes });
|
||||
return with_attributes;
|
||||
}
|
||||
|
||||
auto storage = static_cast<const GenericIndexedPropertyStorage&>(*m_storage);
|
||||
auto& storage = static_cast<const GenericIndexedPropertyStorage&>(*m_storage);
|
||||
auto values = storage.packed_elements();
|
||||
values.ensure_capacity(values.size() + storage.sparse_elements().size());
|
||||
for (auto& entry : storage.sparse_elements())
|
||||
|
@ -374,7 +374,7 @@ Vector<ValueAndAttributes> IndexedProperties::values_unordered() const
|
|||
|
||||
void IndexedProperties::switch_to_generic_storage()
|
||||
{
|
||||
auto storage = static_cast<const SimpleIndexedPropertyStorage&>(*m_storage);
|
||||
auto& storage = static_cast<SimpleIndexedPropertyStorage&>(*m_storage);
|
||||
m_storage = make<GenericIndexedPropertyStorage>(move(storage));
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
virtual void set_array_like_size(size_t new_size) override;
|
||||
|
||||
virtual bool is_simple_storage() const override { return true; }
|
||||
Vector<Value> elements() const { return m_packed_elements; }
|
||||
const Vector<Value>& elements() const { return m_packed_elements; }
|
||||
|
||||
private:
|
||||
friend GenericIndexedPropertyStorage;
|
||||
|
@ -109,8 +109,8 @@ public:
|
|||
virtual size_t array_like_size() const override { return m_array_size; }
|
||||
virtual void set_array_like_size(size_t new_size) override;
|
||||
|
||||
Vector<ValueAndAttributes> packed_elements() const { return m_packed_elements; }
|
||||
HashMap<u32, ValueAndAttributes> sparse_elements() const { return m_sparse_elements; }
|
||||
const Vector<ValueAndAttributes>& packed_elements() const { return m_packed_elements; }
|
||||
const HashMap<u32, ValueAndAttributes>& sparse_elements() const { return m_sparse_elements; }
|
||||
|
||||
private:
|
||||
size_t m_array_size { 0 };
|
||||
|
|
Loading…
Add table
Reference in a new issue