diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp index abc79850e4..1d68751762 100644 --- a/Kernel/CommandLine.cpp +++ b/Kernel/CommandLine.cpp @@ -48,7 +48,7 @@ UNMAP_AFTER_INIT void CommandLine::initialize() } } -UNMAP_AFTER_INIT void CommandLine::build_commandline(const String& cmdline_from_bootloader) +UNMAP_AFTER_INIT NonnullOwnPtr CommandLine::build_commandline(StringView cmdline_from_bootloader) { StringBuilder builder; builder.append(cmdline_from_bootloader); @@ -56,7 +56,7 @@ UNMAP_AFTER_INIT void CommandLine::build_commandline(const String& cmdline_from_ builder.append(" "); builder.append(s_embedded_cmd_line); } - m_string = builder.to_string(); + return KString::must_create(builder.string_view()); } UNMAP_AFTER_INIT void CommandLine::add_arguments(const Vector& args) @@ -77,11 +77,11 @@ UNMAP_AFTER_INIT void CommandLine::add_arguments(const Vector& args) } } -UNMAP_AFTER_INIT CommandLine::CommandLine(const String& cmdline_from_bootloader) +UNMAP_AFTER_INIT CommandLine::CommandLine(StringView cmdline_from_bootloader) + : m_string(build_commandline(cmdline_from_bootloader)) { s_the = this; - build_commandline(cmdline_from_bootloader); - const auto& args = m_string.split_view(' '); + const auto& args = m_string->view().split_view(' '); m_params.ensure_capacity(args.size()); add_arguments(args); } diff --git a/Kernel/CommandLine.h b/Kernel/CommandLine.h index a7f9b85840..ca67ae7b4d 100644 --- a/Kernel/CommandLine.h +++ b/Kernel/CommandLine.h @@ -58,7 +58,7 @@ public: BootloaderOnly }; - [[nodiscard]] const String& string() const { return m_string; } + [[nodiscard]] StringView string() const { return m_string->view(); } Optional lookup(StringView key) const; [[nodiscard]] bool contains(StringView key) const; @@ -89,12 +89,12 @@ public: [[nodiscard]] size_t switch_to_tty() const; private: - CommandLine(const String&); + CommandLine(StringView); void add_arguments(const Vector& args); - void build_commandline(const String& cmdline_from_bootloader); + static NonnullOwnPtr build_commandline(StringView cmdline_from_bootloader); - String m_string; + NonnullOwnPtr m_string; HashMap m_params; };