LibJS+LibWeb: Use GC::Weak instead of AK::WeakPtr for GC-allocated types

This makes some common types like JS::Object smaller (by 8 bytes) and
yields a minor speed improvement on many benchmarks.
This commit is contained in:
Andreas Kling 2025-10-16 11:13:54 +02:00 committed by Andreas Kling
parent 25a5ed94d6
commit dfa796a4e4
Notes: github-actions[bot] 2025-10-17 15:25:08 +00:00
36 changed files with 111 additions and 115 deletions

View file

@ -86,7 +86,7 @@ private:
NonnullOwnPtr<DragAndDropEventHandler> m_drag_and_drop_event_handler;
WeakPtr<DOM::EventTarget> m_mousedown_target;
GC::Weak<DOM::EventTarget> m_mousedown_target;
Optional<CSSPixelPoint> m_mousemove_previous_screen_position;

View file

@ -68,7 +68,7 @@ void Page::set_focused_navigable(Badge<EventHandler>, HTML::Navigable& navigable
void Page::navigable_document_destroyed(Badge<DOM::Document>, HTML::Navigable& navigable)
{
if (&navigable == m_focused_navigable.ptr())
m_focused_navigable.clear();
m_focused_navigable = nullptr;
}
void Page::load(URL::URL const& url)
@ -405,7 +405,7 @@ void Page::on_pending_dialog_closed()
}
}
void Page::did_request_color_picker(WeakPtr<HTML::HTMLInputElement> target, Color current_color)
void Page::did_request_color_picker(GC::Weak<HTML::HTMLInputElement> target, Color current_color)
{
if (m_pending_non_blocking_dialog == PendingNonBlockingDialog::None) {
m_pending_non_blocking_dialog = PendingNonBlockingDialog::ColorPicker;
@ -425,12 +425,12 @@ void Page::color_picker_update(Optional<Color> picked_color, HTML::ColorPickerUp
auto& input_element = as<HTML::HTMLInputElement>(*m_pending_non_blocking_dialog_target);
input_element.did_pick_color(move(picked_color), state);
if (state == HTML::ColorPickerUpdateState::Closed)
m_pending_non_blocking_dialog_target.clear();
m_pending_non_blocking_dialog_target = nullptr;
}
}
}
void Page::did_request_file_picker(WeakPtr<HTML::HTMLInputElement> target, HTML::FileFilter const& accepted_file_types, HTML::AllowMultipleFiles allow_multiple_files)
void Page::did_request_file_picker(GC::Weak<HTML::HTMLInputElement> target, HTML::FileFilter const& accepted_file_types, HTML::AllowMultipleFiles allow_multiple_files)
{
if (m_pending_non_blocking_dialog == PendingNonBlockingDialog::None) {
m_pending_non_blocking_dialog = PendingNonBlockingDialog::FilePicker;
@ -449,12 +449,12 @@ void Page::file_picker_closed(Span<HTML::SelectedFile> selected_files)
auto& input_element = as<HTML::HTMLInputElement>(*m_pending_non_blocking_dialog_target);
input_element.did_select_files(selected_files);
m_pending_non_blocking_dialog_target.clear();
m_pending_non_blocking_dialog_target = nullptr;
}
}
}
void Page::did_request_select_dropdown(WeakPtr<HTML::HTMLSelectElement> target, Web::CSSPixelPoint content_position, Web::CSSPixels minimum_width, Vector<Web::HTML::SelectItem> items)
void Page::did_request_select_dropdown(GC::Weak<HTML::HTMLSelectElement> target, Web::CSSPixelPoint content_position, Web::CSSPixels minimum_width, Vector<Web::HTML::SelectItem> items)
{
if (m_pending_non_blocking_dialog == PendingNonBlockingDialog::None) {
m_pending_non_blocking_dialog = PendingNonBlockingDialog::Select;
@ -471,7 +471,7 @@ void Page::select_dropdown_closed(Optional<u32> const& selected_item_id)
if (m_pending_non_blocking_dialog_target) {
auto& select_element = as<HTML::HTMLSelectElement>(*m_pending_non_blocking_dialog_target);
select_element.did_select_item(selected_item_id);
m_pending_non_blocking_dialog_target.clear();
m_pending_non_blocking_dialog_target = nullptr;
}
}
}

View file

@ -9,8 +9,8 @@
#pragma once
#include <AK/WeakPtr.h>
#include <LibGC/Root.h>
#include <LibGC/Weak.h>
#include <LibGfx/Cursor.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Palette.h>
@ -159,13 +159,13 @@ public:
void dismiss_dialog(GC::Ref<GC::Function<void()>> on_dialog_closed);
void accept_dialog(GC::Ref<GC::Function<void()>> on_dialog_closed);
void did_request_color_picker(WeakPtr<HTML::HTMLInputElement> target, Color current_color);
void did_request_color_picker(GC::Weak<HTML::HTMLInputElement> target, Color current_color);
void color_picker_update(Optional<Color> picked_color, HTML::ColorPickerUpdateState state);
void did_request_file_picker(WeakPtr<HTML::HTMLInputElement> target, HTML::FileFilter const& accepted_file_types, HTML::AllowMultipleFiles);
void did_request_file_picker(GC::Weak<HTML::HTMLInputElement> target, HTML::FileFilter const& accepted_file_types, HTML::AllowMultipleFiles);
void file_picker_closed(Span<HTML::SelectedFile> selected_files);
void did_request_select_dropdown(WeakPtr<HTML::HTMLSelectElement> target, Web::CSSPixelPoint content_position, Web::CSSPixels minimum_width, Vector<Web::HTML::SelectItem> items);
void did_request_select_dropdown(GC::Weak<HTML::HTMLSelectElement> target, Web::CSSPixelPoint content_position, Web::CSSPixels minimum_width, Vector<Web::HTML::SelectItem> items);
void select_dropdown_closed(Optional<u32> const& selected_item_id);
using ClipboardRequest = GC::Ref<GC::Function<void(Vector<Clipboard::SystemClipboardItem>)>>;
@ -246,7 +246,7 @@ private:
GC::Ref<PageClient> m_client;
WeakPtr<HTML::Navigable> m_focused_navigable;
GC::Weak<HTML::Navigable> m_focused_navigable;
GC::Ptr<HTML::TraversableNavigable> m_top_level_traversable;
@ -275,7 +275,7 @@ private:
GC::Ptr<GC::Function<void()>> m_on_pending_dialog_closed;
PendingNonBlockingDialog m_pending_non_blocking_dialog { PendingNonBlockingDialog::None };
WeakPtr<HTML::HTMLElement> m_pending_non_blocking_dialog_target;
GC::Weak<HTML::HTMLElement> m_pending_non_blocking_dialog_target;
HashMap<u64, ClipboardRequest> m_pending_clipboard_requests;
u64 m_next_clipboard_request_id { 0 };