From 359d6e7b0b0ef7add9eb2015d0dd664a82cf73d7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 6 Mar 2023 17:16:25 +0100 Subject: [PATCH] Everywhere: Stop using NonnullOwnPtrVector Same as NonnullRefPtrVector: weird semantics, questionable benefits. --- Kernel/Bus/VirtIO/Device.h | 6 +- Kernel/CommandLine.cpp | 4 +- Kernel/CommandLine.h | 2 +- Kernel/Coredump.cpp | 4 +- Kernel/FileSystem/ProcFS/ProcessExposed.cpp | 2 +- Kernel/Memory/MemoryManager.cpp | 18 ++--- Kernel/Memory/MemoryManager.h | 2 +- Kernel/Memory/PhysicalRegion.cpp | 10 +-- Kernel/Memory/PhysicalRegion.h | 2 +- Kernel/Net/Realtek/RTL8168NetworkAdapter.cpp | 8 +-- Kernel/Net/Realtek/RTL8168NetworkAdapter.h | 4 +- Kernel/Process.cpp | 2 +- Kernel/Process.h | 14 ++-- Kernel/Syscalls/execve.cpp | 30 ++++---- Ladybird/BrowserWindow.cpp | 6 +- Ladybird/BrowserWindow.h | 2 +- Tests/AK/TestIntrusiveRedBlackTree.cpp | 4 +- Tests/AK/TestVector.cpp | 2 +- .../Applications/PixelPaint/ToolboxWidget.cpp | 2 +- .../Applications/PixelPaint/ToolboxWidget.h | 4 +- .../SystemMonitor/ProcessModel.cpp | 38 ++++++---- .../Applications/SystemMonitor/ProcessModel.h | 8 +-- Userland/Applications/SystemMonitor/main.cpp | 6 +- .../DevTools/HackStudio/ClassViewWidget.cpp | 26 +++---- .../DevTools/HackStudio/ClassViewWidget.h | 4 +- .../HackStudio/Debugger/VariablesModel.cpp | 4 +- .../HackStudio/Debugger/VariablesModel.h | 4 +- Userland/DevTools/Inspector/RemoteObject.h | 2 +- .../Inspector/RemoteObjectGraphModel.cpp | 4 +- .../Inspector/RemoteObjectPropertyModel.cpp | 16 ++--- .../Inspector/RemoteObjectPropertyModel.h | 2 +- Userland/DevTools/Inspector/RemoteProcess.cpp | 4 +- Userland/DevTools/Inspector/RemoteProcess.h | 4 +- Userland/DevTools/Profiler/Profile.cpp | 10 +-- .../DevTools/UserspaceEmulator/Emulator.h | 6 +- Userland/DevTools/UserspaceEmulator/SoftMMU.h | 2 +- Userland/DevTools/UserspaceEmulator/main.cpp | 4 +- Userland/Games/GameOfLife/BoardWidget.h | 4 +- Userland/Libraries/LibCoredump/Inspector.cpp | 2 +- Userland/Libraries/LibCoredump/Inspector.h | 2 +- Userland/Libraries/LibDebug/DebugInfo.cpp | 4 +- Userland/Libraries/LibDebug/DebugInfo.h | 4 +- Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h | 4 +- Userland/Libraries/LibGUI/CommandPalette.cpp | 8 +-- Userland/Libraries/LibGUI/EditingEngine.cpp | 4 +- Userland/Libraries/LibGUI/FileSystemModel.cpp | 22 +++--- Userland/Libraries/LibGUI/FileSystemModel.h | 2 +- Userland/Libraries/LibGUI/Menu.cpp | 10 +-- Userland/Libraries/LibGUI/Menu.h | 4 +- .../Libraries/LibGUI/RegularEditingEngine.cpp | 2 +- Userland/Libraries/LibGUI/TextDocument.cpp | 2 +- Userland/Libraries/LibGUI/TextDocument.h | 10 +-- Userland/Libraries/LibGUI/TextEditor.cpp | 46 ++++++------ Userland/Libraries/LibGUI/TextEditor.h | 6 +- Userland/Libraries/LibGUI/Toolbar.cpp | 26 +++---- Userland/Libraries/LibGUI/Toolbar.h | 2 +- Userland/Libraries/LibGUI/UndoStack.cpp | 10 +-- Userland/Libraries/LibGUI/UndoStack.h | 2 +- Userland/Libraries/LibGemini/Document.cpp | 2 +- Userland/Libraries/LibGemini/Document.h | 2 +- Userland/Libraries/LibGfx/GIFLoader.cpp | 50 ++++++------- Userland/Libraries/LibHTTP/Job.cpp | 6 +- Userland/Libraries/LibHTTP/Job.h | 2 +- Userland/Libraries/LibIPC/Connection.cpp | 8 +-- Userland/Libraries/LibIPC/Connection.h | 2 +- .../Libraries/LibJS/Bytecode/Executable.cpp | 2 +- .../Libraries/LibJS/Bytecode/Executable.h | 2 +- .../Libraries/LibJS/Bytecode/Generator.cpp | 4 +- Userland/Libraries/LibJS/Bytecode/Generator.h | 4 +- .../Libraries/LibJS/Bytecode/Interpreter.cpp | 2 +- .../LibJS/Bytecode/Pass/GenerateCFG.cpp | 2 +- .../LibJS/Bytecode/Pass/LoadElimination.cpp | 8 +-- .../LibJS/Bytecode/Pass/MergeBlocks.cpp | 2 +- .../LibJS/Bytecode/Pass/PlaceBlocks.cpp | 2 +- .../LibJS/Bytecode/Pass/UnifySameBlocks.cpp | 8 +-- .../Libraries/LibJS/Bytecode/PassManager.h | 4 +- .../Libraries/LibMarkdown/ContainerBlock.cpp | 18 ++--- .../Libraries/LibMarkdown/ContainerBlock.h | 6 +- Userland/Libraries/LibMarkdown/List.cpp | 2 +- Userland/Libraries/LibMarkdown/Text.cpp | 16 ++--- Userland/Libraries/LibMarkdown/Text.h | 2 +- Userland/Libraries/LibVT/Terminal.cpp | 72 +++++++++---------- Userland/Libraries/LibVT/Terminal.h | 24 +++---- Userland/Libraries/LibWeb/CSS/MediaQuery.cpp | 12 ++-- Userland/Libraries/LibWeb/CSS/MediaQuery.h | 6 +- .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 10 +-- Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 48 ++++++------- Userland/Libraries/LibWeb/CSS/StyleValue.h | 12 ++-- .../WebAssembly/WebAssemblyInstanceObject.h | 2 +- .../WebAssembly/WebAssemblyModuleObject.h | 2 +- .../LibWeb/WebAssembly/WebAssemblyObject.cpp | 8 +-- .../LibWeb/WebAssembly/WebAssemblyObject.h | 4 +- Userland/Libraries/LibXML/DOM/Node.cpp | 2 +- Userland/Libraries/LibXML/DOM/Node.h | 2 +- Userland/Libraries/LibXML/Parser/Parser.cpp | 2 +- Userland/Services/ChessEngine/MCTSTree.cpp | 18 ++--- Userland/Services/ChessEngine/MCTSTree.h | 2 +- .../RequestServer/ConnectionCache.cpp | 16 ++--- .../Services/RequestServer/ConnectionCache.h | 14 ++-- Userland/Services/WebDriver/Client.cpp | 8 +-- Userland/Services/WebDriver/Client.h | 2 +- Userland/Services/WindowServer/Menu.cpp | 54 +++++++------- Userland/Services/WindowServer/Menu.h | 8 +-- .../Services/WindowServer/WindowFrame.cpp | 12 ++-- Userland/Services/WindowServer/WindowFrame.h | 2 +- .../Services/WindowServer/WindowManager.cpp | 30 ++++---- .../Services/WindowServer/WindowManager.h | 10 +-- Userland/Shell/Shell.cpp | 16 ++--- Userland/Shell/Shell.h | 6 +- Userland/Utilities/wasm.cpp | 6 +- Userland/Utilities/xml.cpp | 6 +- 111 files changed, 517 insertions(+), 503 deletions(-) diff --git a/Kernel/Bus/VirtIO/Device.h b/Kernel/Bus/VirtIO/Device.h index e185f7a1715..f8269aafe01 100644 --- a/Kernel/Bus/VirtIO/Device.h +++ b/Kernel/Bus/VirtIO/Device.h @@ -144,13 +144,13 @@ protected: Queue& get_queue(u16 queue_index) { VERIFY(queue_index < m_queue_count); - return m_queues[queue_index]; + return *m_queues[queue_index]; } Queue const& get_queue(u16 queue_index) const { VERIFY(queue_index < m_queue_count); - return m_queues[queue_index]; + return *m_queues[queue_index]; } template @@ -190,7 +190,7 @@ private: u8 isr_status(); virtual bool handle_irq(RegisterState const&) override; - NonnullOwnPtrVector m_queues; + Vector> m_queues; Vector m_configs; Configuration const* m_common_cfg { nullptr }; // Cached due to high usage Configuration const* m_notify_cfg { nullptr }; // Cached due to high usage diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp index f234f792501..23245e044fc 100644 --- a/Kernel/CommandLine.cpp +++ b/Kernel/CommandLine.cpp @@ -304,9 +304,9 @@ StringView CommandLine::userspace_init() const return lookup("init"sv).value_or("/bin/SystemServer"sv); } -NonnullOwnPtrVector CommandLine::userspace_init_args() const +Vector> CommandLine::userspace_init_args() const { - NonnullOwnPtrVector args; + Vector> args; auto init_args = lookup("init_args"sv).value_or(""sv).split_view(';'); if (!init_args.is_empty()) diff --git a/Kernel/CommandLine.h b/Kernel/CommandLine.h index 4b015cdf19a..748c0595ac7 100644 --- a/Kernel/CommandLine.h +++ b/Kernel/CommandLine.h @@ -97,7 +97,7 @@ public: [[nodiscard]] bool is_early_boot_console_disabled() const; [[nodiscard]] AHCIResetMode ahci_reset_mode() const; [[nodiscard]] StringView userspace_init() const; - [[nodiscard]] NonnullOwnPtrVector userspace_init_args() const; + [[nodiscard]] Vector> userspace_init_args() const; [[nodiscard]] StringView root_device() const; [[nodiscard]] bool is_nvme_polling_enabled() const; [[nodiscard]] size_t switch_to_tty() const; diff --git a/Kernel/Coredump.cpp b/Kernel/Coredump.cpp index 5794ab7e740..be9d2811ac1 100644 --- a/Kernel/Coredump.cpp +++ b/Kernel/Coredump.cpp @@ -287,14 +287,14 @@ ErrorOr Coredump::create_notes_process_data(auto& builder) const { auto arguments_array = TRY(process_obj.add_array("arguments"sv)); for (auto const& argument : m_process->arguments()) - TRY(arguments_array.add(argument.view())); + TRY(arguments_array.add(argument->view())); TRY(arguments_array.finish()); } { auto environment_array = TRY(process_obj.add_array("environment"sv)); for (auto const& variable : m_process->environment()) - TRY(environment_array.add(variable.view())); + TRY(environment_array.add(variable->view())); TRY(environment_array.finish()); } diff --git a/Kernel/FileSystem/ProcFS/ProcessExposed.cpp b/Kernel/FileSystem/ProcFS/ProcessExposed.cpp index 9e23659d4c9..80db1e54e8c 100644 --- a/Kernel/FileSystem/ProcFS/ProcessExposed.cpp +++ b/Kernel/FileSystem/ProcFS/ProcessExposed.cpp @@ -348,7 +348,7 @@ ErrorOr Process::procfs_get_command_line(KBufferBuilder& builder) const { auto array = TRY(JsonArraySerializer<>::try_create(builder)); for (auto const& arg : arguments()) { - TRY(array.add(arg.view())); + TRY(array.add(arg->view())); } TRY(array.finish()); return {}; diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index 2adc2b90972..6d1c59908cc 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -365,7 +365,7 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map() } for (auto& region : global_data.physical_regions) - global_data.system_memory_info.physical_pages += region.size(); + global_data.system_memory_info.physical_pages += region->size(); register_reserved_ranges(); for (auto& range : global_data.reserved_memory_ranges) { @@ -384,8 +384,8 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map() } for (auto& region : global_data.physical_regions) { - dmesgln("MM: User physical region: {} - {} (size {:#x})", region.lower(), region.upper().offset(-1), PAGE_SIZE * region.size()); - region.initialize_zones(); + dmesgln("MM: User physical region: {} - {} (size {:#x})", region->lower(), region->upper().offset(-1), PAGE_SIZE * region->size()); + region->initialize_zones(); } }); } @@ -425,8 +425,8 @@ UNMAP_AFTER_INIT void MemoryManager::initialize_physical_pages() Optional found_region_index; for (size_t i = 0; i < global_data.physical_regions.size(); ++i) { auto& region = global_data.physical_regions[i]; - if (region.size() >= physical_page_array_pages_and_page_tables_count) { - found_region = ®ion; + if (region->size() >= physical_page_array_pages_and_page_tables_count) { + found_region = region; found_region_index = i; break; } @@ -894,10 +894,10 @@ void MemoryManager::deallocate_physical_page(PhysicalAddress paddr) return m_global_data.with([&](auto& global_data) { // Are we returning a user page? for (auto& region : global_data.physical_regions) { - if (!region.contains(paddr)) + if (!region->contains(paddr)) continue; - region.return_page(paddr); + region->return_page(paddr); --global_data.system_memory_info.physical_pages_used; // Always return pages to the uncommitted pool. Pages that were @@ -925,7 +925,7 @@ RefPtr MemoryManager::find_free_physical_page(bool committed) global_data.system_memory_info.physical_pages_uncommitted--; } for (auto& region : global_data.physical_regions) { - page = region.take_free_page(); + page = region->take_free_page(); if (!page.is_null()) { ++global_data.system_memory_info.physical_pages_used; break; @@ -1020,7 +1020,7 @@ ErrorOr>> MemoryManager::allocate_contiguous_ return ENOMEM; for (auto& physical_region : global_data.physical_regions) { - auto physical_pages = physical_region.take_contiguous_free_pages(page_count); + auto physical_pages = physical_region->take_contiguous_free_pages(page_count); if (!physical_pages.is_empty()) { global_data.system_memory_info.physical_pages_uncommitted -= page_count; global_data.system_memory_info.physical_pages_used += page_count; diff --git a/Kernel/Memory/MemoryManager.h b/Kernel/Memory/MemoryManager.h index 8ec09e9786c..ddd0f9d7a55 100644 --- a/Kernel/Memory/MemoryManager.h +++ b/Kernel/Memory/MemoryManager.h @@ -292,7 +292,7 @@ private: SystemMemoryInfo system_memory_info; - NonnullOwnPtrVector physical_regions; + Vector> physical_regions; OwnPtr physical_pages_region; RegionTree region_tree; diff --git a/Kernel/Memory/PhysicalRegion.cpp b/Kernel/Memory/PhysicalRegion.cpp index 98f80858666..71cd9d58ea0 100644 --- a/Kernel/Memory/PhysicalRegion.cpp +++ b/Kernel/Memory/PhysicalRegion.cpp @@ -46,7 +46,7 @@ void PhysicalRegion::initialize_zones() while (remaining_pages >= pages_per_zone) { m_zones.append(adopt_nonnull_own_or_enomem(new (nothrow) PhysicalZone(base_address, pages_per_zone)).release_value_but_fixme_should_propagate_errors()); base_address = base_address.offset(pages_per_zone * PAGE_SIZE); - m_usable_zones.append(m_zones.last()); + m_usable_zones.append(*m_zones.last()); remaining_pages -= pages_per_zone; ++zone_count; } @@ -131,10 +131,10 @@ void PhysicalRegion::return_page(PhysicalAddress paddr) zone_index = m_large_zones + (paddr.get() - small_zone_base) / small_zone_size; auto& zone = m_zones[zone_index]; - VERIFY(zone.contains(paddr)); - zone.deallocate_block(paddr, 0); - if (m_full_zones.contains(zone)) - m_usable_zones.append(zone); + VERIFY(zone->contains(paddr)); + zone->deallocate_block(paddr, 0); + if (m_full_zones.contains(*zone)) + m_usable_zones.append(*zone); } } diff --git a/Kernel/Memory/PhysicalRegion.h b/Kernel/Memory/PhysicalRegion.h index 0a124b97409..9843a962659 100644 --- a/Kernel/Memory/PhysicalRegion.h +++ b/Kernel/Memory/PhysicalRegion.h @@ -43,7 +43,7 @@ private: static constexpr size_t large_zone_size = 16 * MiB; static constexpr size_t small_zone_size = 1 * MiB; - NonnullOwnPtrVector m_zones; + Vector> m_zones; size_t m_large_zones { 0 }; diff --git a/Kernel/Net/Realtek/RTL8168NetworkAdapter.cpp b/Kernel/Net/Realtek/RTL8168NetworkAdapter.cpp index 4d74da54d8e..6020d26d3e5 100644 --- a/Kernel/Net/Realtek/RTL8168NetworkAdapter.cpp +++ b/Kernel/Net/Realtek/RTL8168NetworkAdapter.cpp @@ -1103,7 +1103,7 @@ UNMAP_AFTER_INIT void RTL8168NetworkAdapter::initialize_rx_descriptors() descriptor.buffer_size = RX_BUFFER_SIZE; descriptor.flags = RXDescriptor::Ownership; // let the NIC know it can use this descriptor - auto physical_address = m_rx_buffers_regions[i].physical_page(0)->paddr().get(); + auto physical_address = m_rx_buffers_regions[i]->physical_page(0)->paddr().get(); descriptor.buffer_address_low = physical_address & 0xFFFFFFFF; descriptor.buffer_address_high = (u64)physical_address >> 32; // cast to prevent shift count >= with of type warnings in 32 bit systems } @@ -1120,7 +1120,7 @@ UNMAP_AFTER_INIT void RTL8168NetworkAdapter::initialize_tx_descriptors() m_tx_buffers_regions.append(move(region)); descriptor.flags = TXDescriptor::FirstSegment | TXDescriptor::LastSegment; - auto physical_address = m_tx_buffers_regions[i].physical_page(0)->paddr().get(); + auto physical_address = m_tx_buffers_regions[i]->physical_page(0)->paddr().get(); descriptor.buffer_address_low = physical_address & 0xFFFFFFFF; descriptor.buffer_address_high = (u64)physical_address >> 32; } @@ -1213,7 +1213,7 @@ void RTL8168NetworkAdapter::send_raw(ReadonlyBytes payload) } dbgln_if(RTL8168_DEBUG, "RTL8168: Chose descriptor {}", m_tx_free_index); - memcpy(m_tx_buffers_regions[m_tx_free_index].vaddr().as_ptr(), payload.data(), payload.size()); + memcpy(m_tx_buffers_regions[m_tx_free_index]->vaddr().as_ptr(), payload.data(), payload.size()); m_tx_free_index = (m_tx_free_index + 1) % number_of_tx_descriptors; @@ -1247,7 +1247,7 @@ void RTL8168NetworkAdapter::receive() // Our maximum received packet size is smaller than the descriptor buffer size, so packets should never be segmented // if this happens on a real NIC it might not respect that, and we will have to support packet segmentation } else { - did_receive({ m_rx_buffers_regions[descriptor_index].vaddr().as_ptr(), length }); + did_receive({ m_rx_buffers_regions[descriptor_index]->vaddr().as_ptr(), length }); } descriptor.buffer_size = RX_BUFFER_SIZE; diff --git a/Kernel/Net/Realtek/RTL8168NetworkAdapter.h b/Kernel/Net/Realtek/RTL8168NetworkAdapter.h index 2b1c741b08a..4e199d9533b 100644 --- a/Kernel/Net/Realtek/RTL8168NetworkAdapter.h +++ b/Kernel/Net/Realtek/RTL8168NetworkAdapter.h @@ -205,10 +205,10 @@ private: NonnullOwnPtr m_registers_io_window; u32 m_ocp_base_address { 0 }; OwnPtr m_rx_descriptors_region; - NonnullOwnPtrVector m_rx_buffers_regions; + Vector> m_rx_buffers_regions; u16 m_rx_free_index { 0 }; OwnPtr m_tx_descriptors_region; - NonnullOwnPtrVector m_tx_buffers_regions; + Vector> m_tx_buffers_regions; u16 m_tx_free_index { 0 }; bool m_link_up { false }; EntropySource m_entropy_source; diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 2f0d91230dd..283dd57f157 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -217,7 +217,7 @@ void Process::register_new(Process& process) }); } -ErrorOr> Process::try_create_user_process(LockRefPtr& first_thread, StringView path, UserID uid, GroupID gid, NonnullOwnPtrVector arguments, NonnullOwnPtrVector environment, TTY* tty) +ErrorOr> Process::try_create_user_process(LockRefPtr& first_thread, StringView path, UserID uid, GroupID gid, Vector> arguments, Vector> environment, TTY* tty) { auto parts = path.split_view('/'); if (arguments.is_empty()) { diff --git a/Kernel/Process.h b/Kernel/Process.h index 57dd5c1afa6..77cb2b0f310 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -192,7 +192,7 @@ public: } static LockRefPtr create_kernel_process(LockRefPtr& first_thread, NonnullOwnPtr name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes); - static ErrorOr> try_create_user_process(LockRefPtr& first_thread, StringView path, UserID, GroupID, NonnullOwnPtrVector arguments, NonnullOwnPtrVector environment, TTY*); + static ErrorOr> try_create_user_process(LockRefPtr& first_thread, StringView path, UserID, GroupID, Vector> arguments, Vector> environment, TTY*); static void register_new(Process&); ~Process(); @@ -471,10 +471,10 @@ public: static constexpr size_t max_arguments_size = Thread::default_userspace_stack_size / 8; static constexpr size_t max_environment_size = Thread::default_userspace_stack_size / 8; static constexpr size_t max_auxiliary_size = Thread::default_userspace_stack_size / 8; - NonnullOwnPtrVector const& arguments() const { return m_arguments; }; - NonnullOwnPtrVector const& environment() const { return m_environment; }; + Vector> const& arguments() const { return m_arguments; }; + Vector> const& environment() const { return m_environment; }; - ErrorOr exec(NonnullOwnPtr path, NonnullOwnPtrVector arguments, NonnullOwnPtrVector environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth = 0); + ErrorOr exec(NonnullOwnPtr path, Vector> arguments, Vector> environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth = 0); ErrorOr load(NonnullLockRefPtr main_program_description, LockRefPtr interpreter_description, const ElfW(Ehdr) & main_program_header); @@ -606,7 +606,7 @@ private: bool create_perf_events_buffer_if_needed(); void delete_perf_events_buffer(); - ErrorOr do_exec(NonnullLockRefPtr main_program_description, NonnullOwnPtrVector arguments, NonnullOwnPtrVector environment, LockRefPtr interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header); + ErrorOr do_exec(NonnullLockRefPtr main_program_description, Vector> arguments, Vector> environment, LockRefPtr interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header); ErrorOr do_write(OpenFileDescription&, UserOrKernelBuffer const&, size_t, Optional = {}); ErrorOr do_statvfs(FileSystem const& path, Custody const*, statvfs* buf); @@ -846,8 +846,8 @@ private: SpinlockProtected, LockRank::None> m_current_directory; - NonnullOwnPtrVector m_arguments; - NonnullOwnPtrVector m_environment; + Vector> m_arguments; + Vector> m_environment; LockRefPtr m_tty; diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 9d8fcf16dc8..1cb21d7e7c2 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -43,16 +43,16 @@ struct LoadResult { static constexpr size_t auxiliary_vector_size = 15; static Array generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, UserID uid, UserID euid, GroupID gid, GroupID egid, StringView executable_path, Optional const& main_program_fd_allocation); -static bool validate_stack_size(NonnullOwnPtrVector const& arguments, NonnullOwnPtrVector& environment, Array const& auxiliary) +static bool validate_stack_size(Vector> const& arguments, Vector>& environment, Array const& auxiliary) { size_t total_arguments_size = 0; size_t total_environment_size = 0; size_t total_auxiliary_size = 0; for (auto const& a : arguments) - total_arguments_size += a.length() + 1; + total_arguments_size += a->length() + 1; for (auto const& e : environment) - total_environment_size += e.length() + 1; + total_environment_size += e->length() + 1; for (auto const& v : auxiliary) { if (!v.optional_string.is_empty()) total_auxiliary_size += round_up_to_power_of_two(v.optional_string.length() + 1, sizeof(FlatPtr)); @@ -77,8 +77,8 @@ static bool validate_stack_size(NonnullOwnPtrVector const& arguments, N return true; } -static ErrorOr make_userspace_context_for_main_thread([[maybe_unused]] ThreadRegisters& regs, Memory::Region& region, NonnullOwnPtrVector const& arguments, - NonnullOwnPtrVector const& environment, Array auxiliary_values) +static ErrorOr make_userspace_context_for_main_thread([[maybe_unused]] ThreadRegisters& regs, Memory::Region& region, Vector> const& arguments, + Vector> const& environment, Array auxiliary_values) { FlatPtr new_sp = region.range().end().get(); @@ -108,13 +108,13 @@ static ErrorOr make_userspace_context_for_main_thread([[maybe_unused]] Vector argv_entries; for (auto const& argument : arguments) { - push_string_on_new_stack(argument.view()); + push_string_on_new_stack(argument->view()); TRY(argv_entries.try_append(new_sp)); } Vector env_entries; for (auto const& variable : environment) { - push_string_on_new_stack(variable.view()); + push_string_on_new_stack(variable->view()); TRY(env_entries.try_append(new_sp)); } @@ -471,7 +471,7 @@ void Process::clear_signal_handlers_for_exec() } } -ErrorOr Process::do_exec(NonnullLockRefPtr main_program_description, NonnullOwnPtrVector arguments, NonnullOwnPtrVector environment, +ErrorOr Process::do_exec(NonnullLockRefPtr main_program_description, Vector> arguments, Vector> environment, LockRefPtr interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header) { VERIFY(is_user_process()); @@ -746,12 +746,12 @@ static Array generate_auxiliary_vect } }; } -static ErrorOr> find_shebang_interpreter_for_executable(char const first_page[], size_t nread) +static ErrorOr>> find_shebang_interpreter_for_executable(char const first_page[], size_t nread) { int word_start = 2; size_t word_length = 0; if (nread > 2 && first_page[0] == '#' && first_page[1] == '!') { - NonnullOwnPtrVector interpreter_words; + Vector> interpreter_words; for (size_t i = 2; i < nread; ++i) { if (first_page[i] == '\n') { @@ -851,7 +851,7 @@ ErrorOr> Process::find_elf_interpreter_for_execu return nullptr; } -ErrorOr Process::exec(NonnullOwnPtr path, NonnullOwnPtrVector arguments, NonnullOwnPtrVector environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth) +ErrorOr Process::exec(NonnullOwnPtr path, Vector> arguments, Vector> environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth) { if (recursion_depth > 2) { dbgln("exec({}): SHENANIGANS! recursed too far trying to find #! interpreter", path); @@ -886,8 +886,8 @@ ErrorOr Process::exec(NonnullOwnPtr path, NonnullOwnPtrVectortry_clone()); + arguments[0] = move(path); TRY(arguments.try_prepend(move(shebang_words))); return exec(move(shebang_path), move(arguments), move(environment), new_main_thread, previous_interrupts_state, ++recursion_depth); } @@ -949,10 +949,10 @@ ErrorOr Process::sys$execve(Userspace return {}; }; - NonnullOwnPtrVector arguments; + Vector> arguments; TRY(copy_user_strings(params.arguments, arguments)); - NonnullOwnPtrVector environment; + Vector> environment; TRY(copy_user_strings(params.environment, environment)); TRY(exec(move(path), move(arguments), move(environment), new_main_thread, previous_interrupts_state)); diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index 14cc23dfe7d..0b03c0eb7f3 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -456,21 +456,21 @@ void BrowserWindow::open_previous_tab() void BrowserWindow::enable_auto_color_scheme() { for (auto& tab : m_tabs) { - tab.view().set_preferred_color_scheme(Web::CSS::PreferredColorScheme::Auto); + tab->view().set_preferred_color_scheme(Web::CSS::PreferredColorScheme::Auto); } } void BrowserWindow::enable_light_color_scheme() { for (auto& tab : m_tabs) { - tab.view().set_preferred_color_scheme(Web::CSS::PreferredColorScheme::Light); + tab->view().set_preferred_color_scheme(Web::CSS::PreferredColorScheme::Light); } } void BrowserWindow::enable_dark_color_scheme() { for (auto& tab : m_tabs) { - tab.view().set_preferred_color_scheme(Web::CSS::PreferredColorScheme::Dark); + tab->view().set_preferred_color_scheme(Web::CSS::PreferredColorScheme::Dark); } } diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h index 5a5438dc946..c3677a0c3c4 100644 --- a/Ladybird/BrowserWindow.h +++ b/Ladybird/BrowserWindow.h @@ -61,7 +61,7 @@ private: void debug_request(DeprecatedString const& request, DeprecatedString const& argument = ""); QTabWidget* m_tabs_container { nullptr }; - NonnullOwnPtrVector m_tabs; + Vector> m_tabs; Tab* m_current_tab { nullptr }; Browser::CookieJar& m_cookie_jar; diff --git a/Tests/AK/TestIntrusiveRedBlackTree.cpp b/Tests/AK/TestIntrusiveRedBlackTree.cpp index 6492c577704..587cede5912 100644 --- a/Tests/AK/TestIntrusiveRedBlackTree.cpp +++ b/Tests/AK/TestIntrusiveRedBlackTree.cpp @@ -72,7 +72,7 @@ TEST_CASE(key_ordered_iteration) { constexpr auto amount = 10000; IntrusiveRBTree test; - NonnullOwnPtrVector m_entries; + Vector> m_entries; Array keys {}; // generate random key order @@ -105,7 +105,7 @@ TEST_CASE(key_ordered_iteration) TEST_CASE(clear) { IntrusiveRBTree test; - NonnullOwnPtrVector m_entries; + Vector> m_entries; for (size_t i = 0; i < 1000; i++) { auto entry = make(i); test.insert(i, *entry); diff --git a/Tests/AK/TestVector.cpp b/Tests/AK/TestVector.cpp index fafa8f55648..6e6fb38e185 100644 --- a/Tests/AK/TestVector.cpp +++ b/Tests/AK/TestVector.cpp @@ -288,7 +288,7 @@ TEST_CASE(nonnullownptrvector) struct Object { DeprecatedString string; }; - NonnullOwnPtrVector objects; + Vector> objects; objects.append(make()); EXPECT_EQ(objects.size(), 1u); diff --git a/Userland/Applications/PixelPaint/ToolboxWidget.cpp b/Userland/Applications/PixelPaint/ToolboxWidget.cpp index f8bb4341f1a..334e71cf970 100644 --- a/Userland/Applications/PixelPaint/ToolboxWidget.cpp +++ b/Userland/Applications/PixelPaint/ToolboxWidget.cpp @@ -71,7 +71,7 @@ void ToolboxWidget::setup_tools() m_tools.append(move(tool)); if (is_default_tool) { VERIFY(m_active_tool == nullptr); - m_active_tool = &m_tools[m_tools.size() - 1]; + m_active_tool = m_tools[m_tools.size() - 1]; action->set_checked(true); } }; diff --git a/Userland/Applications/PixelPaint/ToolboxWidget.h b/Userland/Applications/PixelPaint/ToolboxWidget.h index 789885802b2..1c1632e3608 100644 --- a/Userland/Applications/PixelPaint/ToolboxWidget.h +++ b/Userland/Applications/PixelPaint/ToolboxWidget.h @@ -27,7 +27,7 @@ public: void for_each_tool(Callback callback) { for (auto& tool : m_tools) - callback(tool); + callback(*tool); } Tool* active_tool() const { return m_active_tool; } @@ -40,7 +40,7 @@ private: explicit ToolboxWidget(); RefPtr m_toolbar; GUI::ActionGroup m_action_group; - NonnullOwnPtrVector m_tools; + Vector> m_tools; Tool* m_active_tool { nullptr }; }; diff --git a/Userland/Applications/SystemMonitor/ProcessModel.cpp b/Userland/Applications/SystemMonitor/ProcessModel.cpp index c84da311f05..c38d7f90f28 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.cpp +++ b/Userland/Applications/SystemMonitor/ProcessModel.cpp @@ -350,7 +350,7 @@ GUI::ModelIndex ProcessModel::index(int row, int column, GUI::ModelIndex const& if (!parent.is_valid()) { if (row >= static_cast(m_processes.size())) return {}; - auto corresponding_thread = m_processes[row].main_thread(); + auto corresponding_thread = m_processes[row]->main_thread(); if (!corresponding_thread.has_value()) return {}; return create_index(row, column, corresponding_thread.release_value().ptr()); @@ -368,8 +368,14 @@ int ProcessModel::thread_model_row(Thread const& thread) const { auto const& process = thread.current_state.process; // A process's main thread uses the global process index. - if (process.pid == thread.current_state.pid) - return m_processes.find_first_index(process).value_or(0); + if (process.pid == thread.current_state.pid) { + auto it = m_processes.find_if([&](auto& entry) { + return entry.ptr() == &process; + }); + if (it == m_processes.end()) + return 0; + return it.index(); + } return process.threads.find_first_index(thread).value_or(0); } @@ -387,7 +393,15 @@ GUI::ModelIndex ProcessModel::parent_index(GUI::ModelIndex const& index) const if (!parent.main_thread().has_value()) return {}; - return create_index(m_processes.find_first_index(parent).release_value(), index.column(), parent.main_thread().value().ptr()); + auto process_index = [&]() -> size_t { + auto it = m_processes.find_if([&](auto& entry) { + return entry.ptr() == &parent; + }); + if (it == m_processes.end()) + return 0; + return it.index(); + }(); + return create_index(process_index, index.column(), parent.main_thread().value().ptr()); } Vector ProcessModel::matches(StringView searching, unsigned flags, GUI::ModelIndex const&) @@ -444,7 +458,7 @@ void ProcessModel::update() auto const& process = all_processes.value().processes[i]; NonnullOwnPtr* process_state = nullptr; for (size_t i = 0; i < m_processes.size(); ++i) { - auto* other_process = &m_processes.ptr_at(i); + auto* other_process = &m_processes[i]; if ((*other_process)->pid == process.pid) { process_state = other_process; break; @@ -452,7 +466,7 @@ void ProcessModel::update() } if (!process_state) { m_processes.append(make()); - process_state = &m_processes.ptr_at(m_processes.size() - 1); + process_state = &m_processes.last(); } (*process_state)->pid = process.pid; for (auto& thread : process.threads) { @@ -508,8 +522,8 @@ void ProcessModel::update() } for (auto& c : m_cpus) { - c.total_cpu_percent = 0.0; - c.total_cpu_percent_kernel = 0.0; + c->total_cpu_percent = 0.0; + c->total_cpu_percent_kernel = 0.0; } Vector tids_to_remove; @@ -526,8 +540,8 @@ void ProcessModel::update() thread.current_state.cpu_percent_kernel = total_time_scheduled_diff > 0 ? (float)((time_scheduled_diff_kernel * 1000) / total_time_scheduled_diff) / 10.0f : 0; if (it.value->current_state.pid != 0) { auto& cpu_info = m_cpus[thread.current_state.cpu]; - cpu_info.total_cpu_percent += thread.current_state.cpu_percent; - cpu_info.total_cpu_percent_kernel += thread.current_state.cpu_percent_kernel; + cpu_info->total_cpu_percent += thread.current_state.cpu_percent; + cpu_info->total_cpu_percent_kernel += thread.current_state.cpu_percent_kernel; } } @@ -536,8 +550,8 @@ void ProcessModel::update() m_threads.remove(tid); for (size_t i = 0; i < m_processes.size(); ++i) { auto& process = m_processes[i]; - process.threads.remove_all_matching([&](auto const& thread) { return thread->current_state.tid == tid; }); - if (process.threads.size() == 0) { + process->threads.remove_all_matching([&](auto const& thread) { return thread->current_state.tid == tid; }); + if (process->threads.size() == 0) { m_processes.remove(i); --i; } diff --git a/Userland/Applications/SystemMonitor/ProcessModel.h b/Userland/Applications/SystemMonitor/ProcessModel.h index 3c659538e2d..987de29816a 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.h +++ b/Userland/Applications/SystemMonitor/ProcessModel.h @@ -85,10 +85,10 @@ public: } }; - Function const&)> on_cpu_info_change; + Function> const&)> on_cpu_info_change; Function on_state_update; - NonnullOwnPtrVector const& cpus() const { return m_cpus; } + Vector> const& cpus() const { return m_cpus; } private: ProcessModel(); @@ -243,8 +243,8 @@ private: // The thread list contains the same threads as the Process structs. HashMap> m_threads; - NonnullOwnPtrVector m_processes; - NonnullOwnPtrVector m_cpus; + Vector> m_processes; + Vector> m_cpus; RefPtr m_proc_all; GUI::Icon m_kernel_process_icon; u64 m_total_time_scheduled { 0 }; diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index 6647943ec13..70e57bcfdb7 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -594,11 +594,11 @@ void build_performance_tab(GUI::Widget& graphs_container) cpu_graphs.append(cpu_graph); } } - ProcessModel::the().on_cpu_info_change = [cpu_graphs](NonnullOwnPtrVector const& cpus) mutable { + ProcessModel::the().on_cpu_info_change = [cpu_graphs](Vector> const& cpus) mutable { float sum_cpu = 0; for (size_t i = 0; i < cpus.size(); ++i) { - cpu_graphs[i].add_value({ static_cast(cpus[i].total_cpu_percent), static_cast(cpus[i].total_cpu_percent_kernel) }); - sum_cpu += cpus[i].total_cpu_percent; + cpu_graphs[i].add_value({ static_cast(cpus[i]->total_cpu_percent), static_cast(cpus[i]->total_cpu_percent_kernel) }); + sum_cpu += cpus[i]->total_cpu_percent; } float cpu_usage = sum_cpu / (float)cpus.size(); statusbar->set_text(2, DeprecatedString::formatted("CPU usage: {}%", (int)roundf(cpu_usage))); diff --git a/Userland/DevTools/HackStudio/ClassViewWidget.cpp b/Userland/DevTools/HackStudio/ClassViewWidget.cpp index 0a47deb09ec..da16e727030 100644 --- a/Userland/DevTools/HackStudio/ClassViewWidget.cpp +++ b/Userland/DevTools/HackStudio/ClassViewWidget.cpp @@ -75,13 +75,13 @@ GUI::ModelIndex ClassViewModel::parent_index(const GUI::ModelIndex& index) const if (parent->parent == nullptr) { for (size_t row = 0; row < m_root_scope.size(); row++) { - if (m_root_scope.ptr_at(row).ptr() == parent) + if (m_root_scope[row].ptr() == parent) return create_index(row, 0, parent); } VERIFY_NOT_REACHED(); } for (size_t row = 0; row < parent->parent->children.size(); row++) { - ClassViewNode* child_at_row = parent->parent->children.ptr_at(row).ptr(); + ClassViewNode* child_at_row = parent->parent->children[row].ptr(); if (child_at_row == parent) return create_index(row, 0, parent); } @@ -110,7 +110,7 @@ ClassViewModel::ClassViewModel() }); } -static ClassViewNode& add_child_node(NonnullOwnPtrVector& children, NonnullOwnPtr&& node_ptr, ClassViewNode* parent, CodeComprehension::Declaration const* declaration) +static ClassViewNode& add_child_node(Vector>& children, NonnullOwnPtr&& node_ptr, ClassViewNode* parent, CodeComprehension::Declaration const* declaration) { node_ptr->parent = parent; node_ptr->declaration = declaration; @@ -124,7 +124,7 @@ static ClassViewNode& add_child_node(NonnullOwnPtrVector& childre }, 0, &inserted_index); - return children.at(inserted_index); + return *children.at(inserted_index); } void ClassViewModel::add_declaration(CodeComprehension::Declaration const& decl) @@ -135,21 +135,21 @@ void ClassViewModel::add_declaration(CodeComprehension::Declaration const& decl) if (!scope_parts.is_empty()) { // Traverse declarations tree to the parent of 'decl' for (auto& node : m_root_scope) { - if (node.name == scope_parts.first()) - parent = &node; + if (node->name == scope_parts.first()) + parent = node; } if (parent == nullptr) { m_root_scope.append(make(scope_parts.first())); - parent = &m_root_scope.last(); + parent = m_root_scope.last(); } for (size_t i = 1; i < scope_parts.size(); ++i) { auto& scope = scope_parts[i]; ClassViewNode* next { nullptr }; for (auto& child : parent->children) { - if (child.name == scope) { - next = &child; + if (child->name == scope) { + next = child; break; } } @@ -163,7 +163,7 @@ void ClassViewModel::add_declaration(CodeComprehension::Declaration const& decl) } } - NonnullOwnPtrVector* children_of_parent = nullptr; + Vector>* children_of_parent = nullptr; if (parent) { children_of_parent = &parent->children; } else { @@ -172,10 +172,10 @@ void ClassViewModel::add_declaration(CodeComprehension::Declaration const& decl) bool already_exists = false; for (auto& child : *children_of_parent) { - if (child.name == decl.name) { + if (child->name == decl.name) { already_exists = true; - if (!child.declaration) { - child.declaration = &decl; + if (!child->declaration) { + child->declaration = &decl; } break; } diff --git a/Userland/DevTools/HackStudio/ClassViewWidget.h b/Userland/DevTools/HackStudio/ClassViewWidget.h index f0db0e73fb0..bd717a67b2e 100644 --- a/Userland/DevTools/HackStudio/ClassViewWidget.h +++ b/Userland/DevTools/HackStudio/ClassViewWidget.h @@ -32,7 +32,7 @@ private: struct ClassViewNode { StringView name; CodeComprehension::Declaration const* declaration { nullptr }; - NonnullOwnPtrVector children; + Vector> children; ClassViewNode* parent { nullptr }; explicit ClassViewNode(StringView name) @@ -51,7 +51,7 @@ public: private: explicit ClassViewModel(); void add_declaration(CodeComprehension::Declaration const&); - NonnullOwnPtrVector m_root_scope; + Vector> m_root_scope; }; } diff --git a/Userland/DevTools/HackStudio/Debugger/VariablesModel.cpp b/Userland/DevTools/HackStudio/Debugger/VariablesModel.cpp index c97bcaa7999..5b4fb0dabfa 100644 --- a/Userland/DevTools/HackStudio/Debugger/VariablesModel.cpp +++ b/Userland/DevTools/HackStudio/Debugger/VariablesModel.cpp @@ -35,12 +35,12 @@ GUI::ModelIndex VariablesModel::parent_index(const GUI::ModelIndex& index) const if (parent->parent == nullptr) { for (size_t row = 0; row < m_variables.size(); row++) - if (m_variables.ptr_at(row).ptr() == parent) + if (m_variables[row].ptr() == parent) return create_index(row, 0, parent); VERIFY_NOT_REACHED(); } for (size_t row = 0; row < parent->parent->members.size(); row++) { - Debug::DebugInfo::VariableInfo* child_at_row = parent->parent->members.ptr_at(row).ptr(); + Debug::DebugInfo::VariableInfo* child_at_row = parent->parent->members[row].ptr(); if (child_at_row == parent) return create_index(row, 0, parent); } diff --git a/Userland/DevTools/HackStudio/Debugger/VariablesModel.h b/Userland/DevTools/HackStudio/Debugger/VariablesModel.h index b2fc5a68503..439e8a0a590 100644 --- a/Userland/DevTools/HackStudio/Debugger/VariablesModel.h +++ b/Userland/DevTools/HackStudio/Debugger/VariablesModel.h @@ -28,14 +28,14 @@ public: Debug::ProcessInspector& inspector() { return m_inspector; } private: - explicit VariablesModel(Debug::ProcessInspector& inspector, NonnullOwnPtrVector&& variables, PtraceRegisters const& regs) + explicit VariablesModel(Debug::ProcessInspector& inspector, Vector>&& variables, PtraceRegisters const& regs) : m_variables(move(variables)) , m_regs(regs) , m_inspector(inspector) { m_variable_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"sv).release_value_but_fixme_should_propagate_errors()); } - NonnullOwnPtrVector m_variables; + Vector> m_variables; PtraceRegisters m_regs; GUI::Icon m_variable_icon; diff --git a/Userland/DevTools/Inspector/RemoteObject.h b/Userland/DevTools/Inspector/RemoteObject.h index 344e02c1da9..025acef3696 100644 --- a/Userland/DevTools/Inspector/RemoteObject.h +++ b/Userland/DevTools/Inspector/RemoteObject.h @@ -21,7 +21,7 @@ public: RemoteObjectPropertyModel& property_model(); RemoteObject* parent { nullptr }; - NonnullOwnPtrVector children; + Vector> children; FlatPtr address { 0 }; FlatPtr parent_address { 0 }; diff --git a/Userland/DevTools/Inspector/RemoteObjectGraphModel.cpp b/Userland/DevTools/Inspector/RemoteObjectGraphModel.cpp index d2aa41244e4..97743bf3b99 100644 --- a/Userland/DevTools/Inspector/RemoteObjectGraphModel.cpp +++ b/Userland/DevTools/Inspector/RemoteObjectGraphModel.cpp @@ -45,7 +45,7 @@ GUI::ModelIndex RemoteObjectGraphModel::parent_index(const GUI::ModelIndex& inde // NOTE: If the parent has no parent, it's a root, so we have to look among the remote roots. if (!remote_object.parent->parent) { for (size_t row = 0; row < m_process.roots().size(); ++row) { - if (&m_process.roots()[row] == remote_object.parent) + if (m_process.roots()[row] == remote_object.parent) return create_index(row, 0, remote_object.parent); } VERIFY_NOT_REACHED(); @@ -53,7 +53,7 @@ GUI::ModelIndex RemoteObjectGraphModel::parent_index(const GUI::ModelIndex& inde } for (size_t row = 0; row < remote_object.parent->parent->children.size(); ++row) { - if (&remote_object.parent->parent->children[row] == remote_object.parent) + if (remote_object.parent->parent->children[row] == remote_object.parent) return create_index(row, 0, remote_object.parent); } diff --git a/Userland/DevTools/Inspector/RemoteObjectPropertyModel.cpp b/Userland/DevTools/Inspector/RemoteObjectPropertyModel.cpp index e5503b849cb..02d706de367 100644 --- a/Userland/DevTools/Inspector/RemoteObjectPropertyModel.cpp +++ b/Userland/DevTools/Inspector/RemoteObjectPropertyModel.cpp @@ -111,7 +111,7 @@ GUI::ModelIndex RemoteObjectPropertyModel::index(int row, int column, const GUI: } else { return nullptr; } - return &m_paths.last(); + return m_paths.last(); }; if (!parent.is_valid()) { @@ -176,16 +176,16 @@ JsonPath const* RemoteObjectPropertyModel::cached_path_at(int n, Vectorsize() != prefix.size() + 1) continue; for (size_t i = 0; i < prefix.size(); ++i) { - if (path[i] != prefix[i]) + if ((*path)[i] != prefix[i]) goto do_continue; } if (row_index == 0) { - index_path = &path; + index_path = path; break; } --row_index; @@ -198,15 +198,15 @@ JsonPath const* RemoteObjectPropertyModel::cached_path_at(int n, Vector const& path) const { for (auto& cpath : m_paths) { - if (cpath.size() != path.size()) + if (cpath->size() != path.size()) continue; - for (size_t i = 0; i < cpath.size(); ++i) { - if (cpath[i] != path[i]) + for (size_t i = 0; i < cpath->size(); ++i) { + if ((*cpath)[i] != path[i]) goto do_continue; } - return &cpath; + return cpath; do_continue:; } diff --git a/Userland/DevTools/Inspector/RemoteObjectPropertyModel.h b/Userland/DevTools/Inspector/RemoteObjectPropertyModel.h index 265a75d3581..bc0ff9dbd4d 100644 --- a/Userland/DevTools/Inspector/RemoteObjectPropertyModel.h +++ b/Userland/DevTools/Inspector/RemoteObjectPropertyModel.h @@ -45,7 +45,7 @@ private: JsonPath const* find_cached_path(Vector const& path) const; RemoteObject& m_object; - mutable NonnullOwnPtrVector m_paths; + mutable Vector> m_paths; }; } diff --git a/Userland/DevTools/Inspector/RemoteProcess.cpp b/Userland/DevTools/Inspector/RemoteProcess.cpp index 6cb82e8cd97..5fb6e6dd08e 100644 --- a/Userland/DevTools/Inspector/RemoteProcess.cpp +++ b/Userland/DevTools/Inspector/RemoteProcess.cpp @@ -42,7 +42,7 @@ void RemoteProcess::handle_get_all_objects_response(JsonObject const& response) // FIXME: It would be good if we didn't have to make a local copy of the array value here! auto& object_array = response.get_array("objects"sv).value(); - NonnullOwnPtrVector remote_objects; + Vector> remote_objects; HashMap objects_by_address; for (auto& value : object_array.values()) { @@ -59,7 +59,7 @@ void RemoteProcess::handle_get_all_objects_response(JsonObject const& response) } for (size_t i = 0; i < remote_objects.size(); ++i) { - auto& remote_object = remote_objects.ptr_at(i); + auto& remote_object = remote_objects[i]; auto* parent = objects_by_address.get(remote_object->parent_address).value_or(nullptr); if (!parent) { m_roots.append(move(remote_object)); diff --git a/Userland/DevTools/Inspector/RemoteProcess.h b/Userland/DevTools/Inspector/RemoteProcess.h index b8dd5e32996..7a6e3967cb5 100644 --- a/Userland/DevTools/Inspector/RemoteProcess.h +++ b/Userland/DevTools/Inspector/RemoteProcess.h @@ -25,7 +25,7 @@ public: DeprecatedString const& process_name() const { return m_process_name; } RemoteObjectGraphModel& object_graph_model() { return *m_object_graph_model; } - NonnullOwnPtrVector const& roots() const { return m_roots; } + Vector> const& roots() const { return m_roots; } void set_inspected_object(FlatPtr); @@ -42,7 +42,7 @@ private: pid_t m_pid { -1 }; DeprecatedString m_process_name; NonnullRefPtr m_object_graph_model; - NonnullOwnPtrVector m_roots; + Vector> m_roots; RefPtr m_client; }; diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index 5a9c1d412cb..9834763c038 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -268,7 +268,7 @@ ErrorOr> Profile::load_from_perfcore_file(StringView path return Error::from_string_literal("Malformed profile (events is not an array)"); auto const& perf_events = events_value.value(); - NonnullOwnPtrVector all_processes; + Vector> all_processes; HashMap current_processes; Vector events; EventSerialNumber next_serial; @@ -448,15 +448,15 @@ ErrorOr> Profile::load_from_perfcore_file(StringView path return Error::from_string_literal("No events captured (targeted process was never on CPU)"); quick_sort(all_processes, [](auto& a, auto& b) { - if (a.pid == b.pid) - return a.start_valid < b.start_valid; + if (a->pid == b->pid) + return a->start_valid < b->start_valid; - return a.pid < b.pid; + return a->pid < b->pid; }); Vector processes; for (auto& it : all_processes) - processes.append(move(it)); + processes.append(move(*it)); return adopt_nonnull_own_or_enomem(new (nothrow) Profile(move(processes), move(events))); } diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.h b/Userland/DevTools/UserspaceEmulator/Emulator.h index 6a911466db5..307015578fd 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.h +++ b/Userland/DevTools/UserspaceEmulator/Emulator.h @@ -32,7 +32,7 @@ public: Emulator(DeprecatedString const& executable_path, Vector const& arguments, Vector const& environment); - void set_profiling_details(bool should_dump_profile, size_t instruction_interval, Stream* profile_stream, NonnullOwnPtrVector* profiler_strings, Vector* profiler_string_id_map) + void set_profiling_details(bool should_dump_profile, size_t instruction_interval, Stream* profile_stream, Vector>* profiler_strings, Vector* profiler_string_id_map) { m_is_profiling = should_dump_profile; m_profile_instruction_interval = instruction_interval; @@ -47,7 +47,7 @@ public: } Stream& profile_stream() { return *m_profile_stream; } - NonnullOwnPtrVector& profiler_strings() { return *m_profiler_strings; } + Vector>& profiler_strings() { return *m_profiler_strings; } Vector& profiler_string_id_map() { return *m_profiler_string_id_map; } bool is_profiling() const { return m_is_profiling; } @@ -296,7 +296,7 @@ private: Stream* m_profile_stream { nullptr }; Vector* m_profiler_string_id_map { nullptr }; - NonnullOwnPtrVector* m_profiler_strings { nullptr }; + Vector>* m_profiler_strings { nullptr }; bool m_is_profiling { false }; size_t m_profile_instruction_interval { 0 }; diff --git a/Userland/DevTools/UserspaceEmulator/SoftMMU.h b/Userland/DevTools/UserspaceEmulator/SoftMMU.h index 781aa4a1817..ba379d1a0ef 100644 --- a/Userland/DevTools/UserspaceEmulator/SoftMMU.h +++ b/Userland/DevTools/UserspaceEmulator/SoftMMU.h @@ -144,7 +144,7 @@ private: Region* m_page_to_region_map[786432] = { nullptr }; OwnPtr m_tls_region; - NonnullOwnPtrVector m_regions; + Vector> m_regions; }; } diff --git a/Userland/DevTools/UserspaceEmulator/main.cpp b/Userland/DevTools/UserspaceEmulator/main.cpp index 097128e7988..83498e66e90 100644 --- a/Userland/DevTools/UserspaceEmulator/main.cpp +++ b/Userland/DevTools/UserspaceEmulator/main.cpp @@ -57,7 +57,7 @@ int main(int argc, char** argv, char** env) profile_dump_path = DeprecatedString::formatted("{}.{}.profile", LexicalPath(executable_path).basename(), getpid()); OwnPtr profile_stream; - OwnPtr> profile_strings; + OwnPtr>> profile_strings; OwnPtr> profile_string_id_map; if (dump_profile) { @@ -67,7 +67,7 @@ int main(int argc, char** argv, char** env) return 1; } profile_stream = profile_stream_or_error.release_value(); - profile_strings = make>(); + profile_strings = make>>(); profile_string_id_map = make>(); profile_stream->write_entire_buffer(R"({"events":[)"sv.bytes()).release_value_but_fixme_should_propagate_errors(); diff --git a/Userland/Games/GameOfLife/BoardWidget.h b/Userland/Games/GameOfLife/BoardWidget.h index ef185cb5b99..1bc8b0006df 100644 --- a/Userland/Games/GameOfLife/BoardWidget.h +++ b/Userland/Games/GameOfLife/BoardWidget.h @@ -56,7 +56,7 @@ public: void for_each_pattern(Callback callback) { for (auto& pattern : m_patterns) - callback(pattern); + callback(*pattern); } void run_generation(); @@ -78,7 +78,7 @@ private: Board::RowAndColumn m_last_cell_toggled {}; Board::RowAndColumn m_last_cell_hovered {}; Pattern* m_selected_pattern { nullptr }; - NonnullOwnPtrVector m_patterns; + Vector> m_patterns; NonnullOwnPtr m_board; diff --git a/Userland/Libraries/LibCoredump/Inspector.cpp b/Userland/Libraries/LibCoredump/Inspector.cpp index b78795d571d..185e8811666 100644 --- a/Userland/Libraries/LibCoredump/Inspector.cpp +++ b/Userland/Libraries/LibCoredump/Inspector.cpp @@ -73,7 +73,7 @@ void Inspector::set_registers(PtraceRegisters const&) {}; void Inspector::for_each_loaded_library(Function func) const { for (auto& library : m_loaded_libraries) { - if (func(library) == IterationDecision::Break) + if (func(*library) == IterationDecision::Break) break; } } diff --git a/Userland/Libraries/LibCoredump/Inspector.h b/Userland/Libraries/LibCoredump/Inspector.h index e2714fff19c..adc30771a54 100644 --- a/Userland/Libraries/LibCoredump/Inspector.h +++ b/Userland/Libraries/LibCoredump/Inspector.h @@ -35,7 +35,7 @@ private: NonnullOwnPtr m_reader; - NonnullOwnPtrVector m_loaded_libraries; + Vector> m_loaded_libraries; }; } diff --git a/Userland/Libraries/LibDebug/DebugInfo.cpp b/Userland/Libraries/LibDebug/DebugInfo.cpp index 0c469b3df5f..b437a063f33 100644 --- a/Userland/Libraries/LibDebug/DebugInfo.cpp +++ b/Userland/Libraries/LibDebug/DebugInfo.cpp @@ -160,9 +160,9 @@ Optional DebugInfo::get_address_from_source return result; } -ErrorOr> DebugInfo::get_variables_in_current_scope(PtraceRegisters const& regs) const +ErrorOr>> DebugInfo::get_variables_in_current_scope(PtraceRegisters const& regs) const { - NonnullOwnPtrVector variables; + Vector> variables; // TODO: We can store the scopes in a better data structure for (auto const& scope : m_scopes) { diff --git a/Userland/Libraries/LibDebug/DebugInfo.h b/Userland/Libraries/LibDebug/DebugInfo.h index ffab6543183..57cde07dcca 100644 --- a/Userland/Libraries/LibDebug/DebugInfo.h +++ b/Userland/Libraries/LibDebug/DebugInfo.h @@ -75,7 +75,7 @@ public: Dwarf::EntryTag type_tag; OwnPtr type; - NonnullOwnPtrVector members; + Vector> members; VariableInfo* parent { nullptr }; Vector dimension_sizes; @@ -90,7 +90,7 @@ public: Vector dies_of_variables; }; - ErrorOr> get_variables_in_current_scope(PtraceRegisters const&) const; + ErrorOr>> get_variables_in_current_scope(PtraceRegisters const&) const; Optional get_source_position(FlatPtr address) const; diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h index 24a72e9f750..e0a9c1dcf71 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h @@ -70,7 +70,7 @@ private: ReadonlyBytes m_debug_addr_data; ReadonlyBytes m_debug_ranges_data; - NonnullOwnPtrVector m_compilation_units; + Vector> m_compilation_units; struct DIERange { FlatPtr start_address { 0 }; @@ -93,7 +93,7 @@ template ErrorOr DwarfInfo::for_each_compilation_unit(Callback callback) const { for (auto const& unit : m_compilation_units) { - TRY(callback(unit)); + TRY(callback(*unit)); } return {}; } diff --git a/Userland/Libraries/LibGUI/CommandPalette.cpp b/Userland/Libraries/LibGUI/CommandPalette.cpp index 7f9bf8de60c..c18eb3215d0 100644 --- a/Userland/Libraries/LibGUI/CommandPalette.cpp +++ b/Userland/Libraries/LibGUI/CommandPalette.cpp @@ -243,11 +243,11 @@ void CommandPalette::collect_actions(GUI::Window& parent_window) }; Function collect_actions_from_menu = [&](Menu& menu) { - for (auto menu_item : menu.items()) { - if (menu_item.submenu()) - collect_actions_from_menu(*menu_item.submenu()); + for (auto& menu_item : menu.items()) { + if (menu_item->submenu()) + collect_actions_from_menu(*menu_item->submenu()); - auto* action = menu_item.action(); + auto* action = menu_item->action(); if (should_show_action(action)) actions.set(*action); } diff --git a/Userland/Libraries/LibGUI/EditingEngine.cpp b/Userland/Libraries/LibGUI/EditingEngine.cpp index 984690e3ab1..6a18ded445d 100644 --- a/Userland/Libraries/LibGUI/EditingEngine.cpp +++ b/Userland/Libraries/LibGUI/EditingEngine.cpp @@ -171,7 +171,7 @@ void EditingEngine::move_one_left() m_editor->set_cursor(m_editor->cursor().line(), new_column); } else if (m_editor->cursor().line() > 0) { auto new_line = m_editor->cursor().line() - 1; - auto new_column = m_editor->lines()[new_line].length(); + auto new_column = m_editor->lines()[new_line]->length(); m_editor->set_cursor(new_line, new_column); } } @@ -362,7 +362,7 @@ void EditingEngine::move_to_first_line() void EditingEngine::move_to_last_line() { - m_editor->set_cursor(m_editor->line_count() - 1, m_editor->lines()[m_editor->line_count() - 1].length()); + m_editor->set_cursor(m_editor->line_count() - 1, m_editor->lines()[m_editor->line_count() - 1]->length()); }; void EditingEngine::get_selection_line_boundaries(Badge, size_t& first_line, size_t& last_line) diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index d1d2e18e64b..ca1027f81ea 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -33,7 +33,7 @@ ModelIndex FileSystemModel::Node::index(int column) const if (!m_parent) return {}; for (size_t row = 0; row < m_parent->m_children.size(); ++row) { - if (&m_parent->m_children[row] == this) + if (m_parent->m_children[row] == this) return m_model.create_index(row, column, const_cast(this)); } VERIFY_NOT_REACHED(); @@ -111,8 +111,8 @@ void FileSystemModel::Node::traverse_if_needed() } quick_sort(child_names); - NonnullOwnPtrVector directory_children; - NonnullOwnPtrVector file_children; + Vector> directory_children; + Vector> file_children; for (auto& child_name : child_names) { auto maybe_child = create_child(child_name); @@ -229,7 +229,7 @@ Optional FileSystemModel::node_for_path(Deprecated resolved_path = path; LexicalPath lexical_path(resolved_path); - Node const* node = m_root->m_parent_of_root ? &m_root->m_children.first() : m_root; + Node const* node = m_root->m_parent_of_root ? m_root->m_children.first() : m_root.ptr(); if (lexical_path.string() == "/") return *node; @@ -238,9 +238,9 @@ Optional FileSystemModel::node_for_path(Deprecated auto& part = parts[i]; bool found = false; for (auto& child : node->m_children) { - if (child.name == part) { - const_cast(child).reify_if_needed(); - node = &child; + if (child->name == part) { + const_cast(*child).reify_if_needed(); + node = child; found = true; if (i == parts.size() - 1) return *node; @@ -494,7 +494,7 @@ ModelIndex FileSystemModel::index(int row, int column, ModelIndex const& parent) const_cast(node).reify_if_needed(); if (static_cast(row) >= node.m_children.size()) return {}; - return create_index(row, column, &node.m_children[row]); + return create_index(row, column, node.m_children[row].ptr()); } ModelIndex FileSystemModel::parent_index(ModelIndex const& index) const @@ -801,9 +801,9 @@ Vector FileSystemModel::matches(StringView searching, unsigned flags node.reify_if_needed(); Vector found_indices; for (auto& child : node.m_children) { - if (string_matches(child.name, searching, flags)) { - const_cast(child).reify_if_needed(); - found_indices.append(child.index(Column::Name)); + if (string_matches(child->name, searching, flags)) { + const_cast(*child).reify_if_needed(); + found_indices.append(child->index(Column::Name)); if (flags & FirstMatchOnly) break; } diff --git a/Userland/Libraries/LibGUI/FileSystemModel.h b/Userland/Libraries/LibGUI/FileSystemModel.h index 6f4ac96f6f6..6bf5d48c31e 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.h +++ b/Userland/Libraries/LibGUI/FileSystemModel.h @@ -83,7 +83,7 @@ public: FileSystemModel& m_model; Node* m_parent { nullptr }; - NonnullOwnPtrVector m_children; + Vector> m_children; bool m_has_traversed { false }; bool m_selected { false }; diff --git a/Userland/Libraries/LibGUI/Menu.cpp b/Userland/Libraries/LibGUI/Menu.cpp index 3a5869264ed..8ba2f57fe4e 100644 --- a/Userland/Libraries/LibGUI/Menu.cpp +++ b/Userland/Libraries/LibGUI/Menu.cpp @@ -68,7 +68,7 @@ void Menu::add_action(NonnullRefPtr action) void Menu::remove_all_actions() { for (auto& item : m_items) { - ConnectionToWindowServer::the().async_remove_menu_item(m_menu_id, item.identifier()); + ConnectionToWindowServer::the().async_remove_menu_item(m_menu_id, item->identifier()); } m_items.clear(); } @@ -142,7 +142,7 @@ int Menu::realize_menu(RefPtr default_action) m_current_default_action = default_action; for (size_t i = 0; i < m_items.size(); ++i) { - realize_menu_item(m_items[i], i); + realize_menu_item(*m_items[i], i); } all_menus().set(m_menu_id, this); @@ -168,14 +168,14 @@ Action* Menu::action_at(size_t index) { if (index >= m_items.size()) return nullptr; - return m_items[index].action(); + return m_items[index]->action(); } void Menu::set_children_actions_enabled(bool enabled) { for (auto& item : m_items) { - if (item.action()) - item.action()->set_enabled(enabled); + if (item->action()) + item->action()->set_enabled(enabled); } } diff --git a/Userland/Libraries/LibGUI/Menu.h b/Userland/Libraries/LibGUI/Menu.h index c3abdb0003b..859f8b661ad 100644 --- a/Userland/Libraries/LibGUI/Menu.h +++ b/Userland/Libraries/LibGUI/Menu.h @@ -61,7 +61,7 @@ public: bool is_visible() const { return m_visible; } - NonnullOwnPtrVector const& items() const { return m_items; } + Vector> const& items() const { return m_items; } private: friend class Menubar; @@ -77,7 +77,7 @@ private: int m_menu_id { -1 }; DeprecatedString m_name; RefPtr m_icon; - NonnullOwnPtrVector m_items; + Vector> m_items; WeakPtr m_current_default_action; bool m_visible { false }; diff --git a/Userland/Libraries/LibGUI/RegularEditingEngine.cpp b/Userland/Libraries/LibGUI/RegularEditingEngine.cpp index 347e42007bd..4e0639088d2 100644 --- a/Userland/Libraries/LibGUI/RegularEditingEngine.cpp +++ b/Userland/Libraries/LibGUI/RegularEditingEngine.cpp @@ -61,7 +61,7 @@ void RegularEditingEngine::sort_selected_lines() auto end = lines.begin() + (int)last_line + 1; quick_sort(start, end, [](auto& a, auto& b) { - return strcmp_utf32(a.code_points(), b.code_points(), min(a.length(), b.length())) < 0; + return strcmp_utf32(a->code_points(), b->code_points(), min(a->length(), b->length())) < 0; }); m_editor->did_change(); diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp index c29c2e3220b..3633c2d0f98 100644 --- a/Userland/Libraries/LibGUI/TextDocument.cpp +++ b/Userland/Libraries/LibGUI/TextDocument.cpp @@ -462,7 +462,7 @@ void TextDocument::update_regex_matches(StringView needle) Vector views; for (size_t line = 0; line < m_lines.size(); ++line) { - views.append(m_lines.at(line).view()); + views.append(m_lines[line]->view()); } re.search(views, m_regex_result); m_regex_needs_update = false; diff --git a/Userland/Libraries/LibGUI/TextDocument.h b/Userland/Libraries/LibGUI/TextDocument.h index a79073b7d9e..f6c16f7a74c 100644 --- a/Userland/Libraries/LibGUI/TextDocument.h +++ b/Userland/Libraries/LibGUI/TextDocument.h @@ -70,15 +70,15 @@ public: virtual ~TextDocument() = default; size_t line_count() const { return m_lines.size(); } - TextDocumentLine const& line(size_t line_index) const { return m_lines[line_index]; } - TextDocumentLine& line(size_t line_index) { return m_lines[line_index]; } + TextDocumentLine const& line(size_t line_index) const { return *m_lines[line_index]; } + TextDocumentLine& line(size_t line_index) { return *m_lines[line_index]; } void set_spans(u32 span_collection_index, Vector spans); bool set_text(StringView, AllowCallback = AllowCallback::Yes); - NonnullOwnPtrVector const& lines() const { return m_lines; } - NonnullOwnPtrVector& lines() { return m_lines; } + Vector> const& lines() const { return m_lines; } + Vector>& lines() { return m_lines; } bool has_spans() const { return !m_spans.is_empty(); } Vector& spans() { return m_spans; } @@ -163,7 +163,7 @@ protected: private: void merge_span_collections(); - NonnullOwnPtrVector m_lines; + Vector> m_lines; HashMap> m_span_collections; Vector m_spans; Vector m_folding_regions; diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 9cb591c8b7e..68a47520e50 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -133,8 +133,8 @@ void TextEditor::update_content_size() int content_width = 0; int content_height = 0; for (auto& line : m_line_visual_data) { - content_width = max(line.visual_rect.width(), content_width); - content_height += line.visual_rect.height(); + content_width = max(line->visual_rect.width(), content_width); + content_height += line->visual_rect.height(); } content_width += m_horizontal_content_padding * 2; if (is_right_text_alignment(m_text_alignment)) @@ -167,7 +167,7 @@ TextPosition TextEditor::text_position_at_content_position(Gfx::IntPoint content if (!document().line_is_visible(i)) continue; - auto& rect = m_line_visual_data[i].visual_rect; + auto& rect = m_line_visual_data[i]->visual_rect; if (position.y() >= rect.top() && position.y() <= rect.bottom()) { line_index = i; break; @@ -634,7 +634,7 @@ void TextEditor::paint_event(PaintEvent& event) first_visual_line_with_selection = visual_line_containing(line_index, selection.start().column()); if (selection.end().line() > line_index) - last_visual_line_with_selection = m_line_visual_data[line_index].visual_lines.size(); + last_visual_line_with_selection = m_line_visual_data[line_index]->visual_lines.size(); else last_visual_line_with_selection = visual_line_containing(line_index, selection.end().column()); } @@ -1441,7 +1441,7 @@ Gfx::IntRect TextEditor::line_content_rect(size_t line_index) const line_rect.center_vertically_within({ {}, frame_inner_rect().size() }); return line_rect; } - return m_line_visual_data[line_index].visual_rect; + return m_line_visual_data[line_index]->visual_rect; } void TextEditor::set_cursor_and_focus_line(size_t line, size_t column) @@ -1451,8 +1451,8 @@ void TextEditor::set_cursor_and_focus_line(size_t line, size_t column) if (line > 1 && line < index_max) { int headroom = frame_inner_rect().height() / 3; do { - auto line_data = m_line_visual_data[line]; - headroom -= line_data.visual_rect.height(); + auto const& line_data = m_line_visual_data[line]; + headroom -= line_data->visual_rect.height(); line--; } while (line > 0 && headroom > 0); @@ -1481,8 +1481,8 @@ void TextEditor::set_cursor(TextPosition const& a_position) if (position.line() >= line_count()) position.set_line(line_count() - 1); - if (position.column() > lines()[position.line()].length()) - position.set_column(lines()[position.line()].length()); + if (position.column() > lines()[position.line()]->length()) + position.set_column(lines()[position.line()]->length()); if (m_cursor != position && is_visual_data_up_to_date()) { // NOTE: If the old cursor is no longer valid, repaint everything just in case. @@ -1972,8 +1972,8 @@ void TextEditor::recompute_all_visual_lines() auto folded_region_iterator = folded_regions.begin(); for (size_t line_index = 0; line_index < line_count(); ++line_index) { recompute_visual_lines(line_index, folded_region_iterator); - m_line_visual_data[line_index].visual_rect.set_y(y_offset); - y_offset += m_line_visual_data[line_index].visual_rect.height(); + m_line_visual_data[line_index]->visual_rect.set_y(y_offset); + y_offset += m_line_visual_data[line_index]->visual_rect.height(); } update_content_size(); @@ -2008,7 +2008,7 @@ void TextEditor::recompute_visual_lines(size_t line_index, Vectorvisual_lines.clear_with_capacity(); auto available_width = visible_text_rect_in_inner_coordinates().width(); auto glyph_spacing = font().glyph_spacing(); @@ -2034,7 +2034,7 @@ void TextEditor::recompute_visual_lines(size_t line_index, Vector available_width) { auto start_of_next_visual_line = line.view().iterator_offset(it_before_computing_glyph_width); - visual_data.visual_lines.append(line.view().substring_view(start_of_visual_line, start_of_next_visual_line - start_of_visual_line)); + visual_data->visual_lines.append(line.view().substring_view(start_of_visual_line, start_of_next_visual_line - start_of_visual_line)); line_width_so_far = 0; start_of_visual_line = start_of_next_visual_line; } @@ -2042,7 +2042,7 @@ void TextEditor::recompute_visual_lines(size_t line_index, Vectorvisual_lines.append(line.view().substring_view(start_of_visual_line, line.view().length() - start_of_visual_line)); }; auto wrap_visual_lines_at_words = [&]() { @@ -2057,7 +2057,7 @@ void TextEditor::recompute_visual_lines(size_t line_index, Vector available_width) { - visual_data.visual_lines.append(line.view().substring_view(start_of_visual_line, last_boundary - start_of_visual_line)); + visual_data->visual_lines.append(line.view().substring_view(start_of_visual_line, last_boundary - start_of_visual_line)); line_width_so_far = 0; start_of_visual_line = last_boundary; } @@ -2068,13 +2068,13 @@ void TextEditor::recompute_visual_lines(size_t line_index, Vectorvisual_lines.append(line.view().substring_view(start_of_visual_line, line.view().length() - start_of_visual_line)); }; if (line_is_visible) { switch (wrapping_mode()) { case WrappingMode::NoWrap: - visual_data.visual_lines.append(line.view()); + visual_data->visual_lines.append(line.view()); break; case WrappingMode::WrapAnywhere: wrap_visual_lines_anywhere(); @@ -2086,9 +2086,9 @@ void TextEditor::recompute_visual_lines(size_t line_index, Vector(visual_data.visual_lines.size()) * line_height() }; + visual_data->visual_rect = { m_horizontal_content_padding, 0, available_width, static_cast(visual_data->visual_lines.size()) * line_height() }; else - visual_data.visual_rect = { m_horizontal_content_padding, 0, text_width_for_font(line.view(), font()), line_height() }; + visual_data->visual_rect = { m_horizontal_content_padding, 0, text_width_for_font(line.view(), font()), line_height() }; } template @@ -2100,10 +2100,10 @@ void TextEditor::for_each_visual_line(size_t line_index, Callback callback) cons auto& line = document().line(line_index); auto& visual_data = m_line_visual_data[line_index]; - for (auto visual_line_view : visual_data.visual_lines) { + for (auto visual_line_view : visual_data->visual_lines) { Gfx::IntRect visual_line_rect { - visual_data.visual_rect.x(), - visual_data.visual_rect.y() + ((int)visual_line_index * line_height()), + visual_data->visual_rect.x(), + visual_data->visual_rect.y() + ((int)visual_line_index * line_height()), text_width_for_font(visual_line_view, font()) + font().glyph_spacing(), line_height() }; @@ -2115,7 +2115,7 @@ void TextEditor::for_each_visual_line(size_t line_index, Callback callback) cons visual_line_rect.translate_by(icon_size() + icon_padding(), 0); } size_t start_of_line = visual_line_view.code_points() - line.code_points(); - if (callback(visual_line_rect, visual_line_view, start_of_line, visual_line_index == visual_data.visual_lines.size() - 1) == IterationDecision::Break) + if (callback(visual_line_rect, visual_line_view, start_of_line, visual_line_index == visual_data->visual_lines.size() - 1) == IterationDecision::Break) break; ++visual_line_index; } diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h index 54d55cabe97..e6a3b1c8464 100644 --- a/Userland/Libraries/LibGUI/TextEditor.h +++ b/Userland/Libraries/LibGUI/TextEditor.h @@ -121,8 +121,8 @@ public: size_t line_count() const { return document().line_count(); } TextDocumentLine& line(size_t index) { return document().line(index); } TextDocumentLine const& line(size_t index) const { return document().line(index); } - NonnullOwnPtrVector& lines() { return document().lines(); } - NonnullOwnPtrVector const& lines() const { return document().lines(); } + Vector>& lines() { return document().lines(); } + Vector> const& lines() const { return document().lines(); } int line_height() const; TextPosition cursor() const { return m_cursor; } TextRange normalized_selection() const { return m_selection.normalized(); } @@ -432,7 +432,7 @@ private: Gfx::IntRect visual_rect; }; - NonnullOwnPtrVector m_line_visual_data; + Vector> m_line_visual_data; OwnPtr m_highlighter; OwnPtr m_autocomplete_provider; diff --git a/Userland/Libraries/LibGUI/Toolbar.cpp b/Userland/Libraries/LibGUI/Toolbar.cpp index 50c2cd9aed4..4947b93e1a4 100644 --- a/Userland/Libraries/LibGUI/Toolbar.cpp +++ b/Userland/Libraries/LibGUI/Toolbar.cpp @@ -111,7 +111,7 @@ ErrorOr> Toolbar::try_add_action(Action& action) item->widget->set_fixed_size(m_button_size, m_button_size); m_items.unchecked_append(move(item)); - return *static_cast(m_items.last().widget.ptr()); + return *static_cast(m_items.last()->widget.ptr()); } GUI::Button& Toolbar::add_action(Action& action) @@ -196,12 +196,12 @@ ErrorOr Toolbar::update_overflow_menu() for (size_t i = 0; i < m_items.size() - 1; ++i) { auto& item = m_items.at(i); - auto item_size = is_horizontal ? item.widget->width() : item.widget->height(); + auto item_size = is_horizontal ? item->widget->width() : item->widget->height(); if (position + item_size + margin > toolbar_size) { marginal_index = i; break; } - item.widget->set_visible(true); + item->widget->set_visible(true); position += item_size + spacing; } @@ -216,10 +216,10 @@ ErrorOr Toolbar::update_overflow_menu() if (marginal_index.value() > 0) { for (size_t i = marginal_index.value() - 1; i > 0; --i) { auto& item = m_items.at(i); - auto item_size = is_horizontal ? item.widget->width() : item.widget->height(); + auto item_size = is_horizontal ? item->widget->width() : item->widget->height(); if (position + m_button_size + spacing + margin <= toolbar_size) break; - item.widget->set_visible(false); + item->widget->set_visible(false); position -= item_size + spacing; marginal_index = i; } @@ -228,9 +228,9 @@ ErrorOr Toolbar::update_overflow_menu() if (m_grouped) { for (size_t i = marginal_index.value(); i > 0; --i) { auto& item = m_items.at(i); - if (item.type == Item::Type::Separator) + if (item->type == Item::Type::Separator) break; - item.widget->set_visible(false); + item->widget->set_visible(false); marginal_index = i; } } @@ -247,17 +247,17 @@ ErrorOr Toolbar::update_overflow_menu() auto& item = m_items.at(i); Item* peek_item; if (i > 0) { - peek_item = &m_items.at(i - 1); + peek_item = m_items[i - 1]; if (peek_item->type == Item::Type::Separator) peek_item->widget->set_visible(false); } if (i < m_items.size() - 1) { - item.widget->set_visible(false); - peek_item = &m_items.at(i + 1); - if (item.action) - TRY(m_overflow_menu->try_add_action(*item.action)); + item->widget->set_visible(false); + peek_item = m_items[i + 1]; + if (item->action) + TRY(m_overflow_menu->try_add_action(*item->action)); } - if (item.action && peek_item->type == Item::Type::Separator) + if (item->action && peek_item->type == Item::Type::Separator) TRY(m_overflow_menu->try_add_separator()); } diff --git a/Userland/Libraries/LibGUI/Toolbar.h b/Userland/Libraries/LibGUI/Toolbar.h index 8a9ec2cf1b1..b1f21709756 100644 --- a/Userland/Libraries/LibGUI/Toolbar.h +++ b/Userland/Libraries/LibGUI/Toolbar.h @@ -53,7 +53,7 @@ private: RefPtr action; RefPtr widget; }; - NonnullOwnPtrVector m_items; + Vector> m_items; RefPtr m_overflow_menu; RefPtr m_overflow_action; RefPtr