mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-30 22:54:35 +03:00
Kernel: Avoid some allocations in command line parsing (#3213)
1. Preallocate args hashmap to prevent rehashing. 2. Use move to prevent string copies.
This commit is contained in:
parent
1b075ffe3b
commit
7506adbece
Notes:
sideshowbarker
2024-07-19 03:15:30 +09:00
Author: https://github.com/tryfinally Commit: https://github.com/SerenityOS/serenity/commit/7506adbecea Pull-request: https://github.com/SerenityOS/serenity/pull/3213 Reviewed-by: https://github.com/alimpfard
@ -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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user