mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 21:21:50 +03:00
Everywhere: Mark Vector of mutable references as mutable
The point of a reference type is to behave just like the referred-to type. So, a Foo& should behave just like a Foo. In these cases, we had a const Vector. If it was a const Vector of Foo, iterating over the Vector would only permit taking const references to the individual Foos. However, we had a const Vector of Foo&. The behavior should not change. We should still only be permitted to take const references to the individual Foos. Otherwise, we would be allowed to mutate the individual Foos, which would mutate the elements of the const Vector. This wouldn't modify the stored pointers, but it would modify the objects that the references refer to. Since references should be transparent, this should not be legal. So it should be impossible to get mutable references into a const Vector. Since we need mutable references in these cases to call the mutating member functions, we need to mark the Vector as mutable as well.
This commit is contained in:
parent
294cbb7108
commit
19d9d5bfe1
Notes:
sideshowbarker
2024-07-17 20:49:33 +09:00
Author: https://github.com/creator1creeper1 Commit: https://github.com/SerenityOS/serenity/commit/19d9d5bfe16 Pull-request: https://github.com/SerenityOS/serenity/pull/11771 Reviewed-by: https://github.com/alimpfard
@ -308,7 +308,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
|
||||
m_should_change_selected_cells = false;
|
||||
m_cell_value_editor->on_focusin = [this] { m_should_change_selected_cells = true; };
|
||||
m_cell_value_editor->on_focusout = [this] { m_should_change_selected_cells = false; };
|
||||
m_cell_value_editor->on_change = [cells = move(cells), this] {
|
||||
m_cell_value_editor->on_change = [cells = move(cells), this]() mutable {
|
||||
if (m_should_change_selected_cells) {
|
||||
auto* sheet_ptr = m_selected_view->sheet_if_available();
|
||||
if (!sheet_ptr)
|
||||
|
@ -698,7 +698,7 @@ NonnullRefPtr<GUI::Widget> build_performance_tab()
|
||||
cpu_graphs.append(cpu_graph);
|
||||
}
|
||||
}
|
||||
ProcessModel::the().on_cpu_info_change = [cpu_graphs](const NonnullOwnPtrVector<ProcessModel::CpuInfo>& cpus) {
|
||||
ProcessModel::the().on_cpu_info_change = [cpu_graphs](const NonnullOwnPtrVector<ProcessModel::CpuInfo>& cpus) mutable {
|
||||
float sum_cpu = 0;
|
||||
for (size_t i = 0; i < cpus.size(); ++i) {
|
||||
cpu_graphs[i].add_value({ static_cast<size_t>(cpus[i].total_cpu_percent), static_cast<size_t>(cpus[i].total_cpu_percent_kernel) });
|
||||
|
@ -235,7 +235,7 @@ void MenuManager::close_everyone_not_in_lineage(Menu& menu)
|
||||
close_menus(menus_to_close);
|
||||
}
|
||||
|
||||
void MenuManager::close_menus(const Vector<Menu&>& menus)
|
||||
void MenuManager::close_menus(Vector<Menu&>& menus)
|
||||
{
|
||||
for (auto& menu : menus) {
|
||||
if (&menu == m_current_menu)
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
private:
|
||||
MenuManager();
|
||||
|
||||
void close_menus(const Vector<Menu&>&);
|
||||
void close_menus(Vector<Menu&>&);
|
||||
|
||||
virtual void event(Core::Event&) override;
|
||||
void handle_mouse_event(MouseEvent&);
|
||||
|
Loading…
Reference in New Issue
Block a user