diff options
author | Muhammad Zahalqa <m@tryfinally.com> | 2020-08-23 16:04:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-23 15:04:49 +0200 |
commit | 7506adbecea2f23f72a60a20c68ac5b2bcdfc875 (patch) | |
tree | a2f9e27263ce0ca7ed8836dc3e6ac1a53688d281 /Kernel | |
parent | 1b075ffe3bb4fde03ad527c0c49e3a5f4ede64cf (diff) | |
download | serenity-7506adbecea2f23f72a60a20c68ac5b2bcdfc875.zip |
Kernel: Avoid some allocations in command line parsing (#3213)
1. Preallocate args hashmap to prevent rehashing.
2. Use move to prevent string copies.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/CommandLine.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp index 8b50e7aeec..259fb557f6 100644 --- a/Kernel/CommandLine.cpp +++ b/Kernel/CommandLine.cpp @@ -46,7 +46,9 @@ CommandLine::CommandLine(const String& string) { s_the = this; - for (auto str : m_string.split(' ')) { + const auto& args = m_string.split(' '); + m_params.ensure_capacity(args.size()); + for (auto&& str : args) { if (str == "") { continue; } @@ -54,9 +56,9 @@ CommandLine::CommandLine(const String& string) auto pair = str.split_limit('=', 2); if (pair.size() == 1) { - m_params.set(pair[0], ""); + m_params.set(move(pair[0]), ""); } else { - m_params.set(pair[0], pair[1]); + m_params.set(move(pair[0]), move(pair[1])); } } } |