summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-05-14 13:16:49 +0100
committerAndreas Kling <kling@serenityos.org>2023-05-16 12:54:18 +0200
commite6f7b828c30b97cd0cd3e74a799b5c058d1d87d4 (patch)
treeaf236808269a3b5049d1f9cb927c57fb73bc2c28 /Userland
parent2b02c58cd317a8e01c45de41b08486211f70a4fc (diff)
downloadserenity-e6f7b828c30b97cd0cd3e74a799b5c058d1d87d4.zip
ps: Ensure columns capacity in advance
Also use unchecked_append() in a couple of other places where we can.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/ps.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/Userland/Utilities/ps.cpp b/Userland/Utilities/ps.cpp
index fcf380871b..108b9ae0f8 100644
--- a/Userland/Utilities/ps.cpp
+++ b/Userland/Utilities/ps.cpp
@@ -75,11 +75,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
int cmd_column = -1;
auto add_column = [&](auto title, auto alignment) {
- columns.append({ title, alignment, 0, {} });
+ columns.unchecked_append({ title, alignment, 0, {} });
return columns.size() - 1;
};
if (full_format_flag) {
+ TRY(columns.try_ensure_capacity(8));
uid_column = add_column("UID"_short_string, Alignment::Left);
pid_column = add_column("PID"_short_string, Alignment::Right);
ppid_column = add_column("PPID"_short_string, Alignment::Right);
@@ -89,6 +90,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
tty_column = add_column("TTY"_short_string, Alignment::Left);
cmd_column = add_column("CMD"_short_string, Alignment::Left);
} else {
+ TRY(columns.try_ensure_capacity(3));
pid_column = add_column("PID"_short_string, Alignment::Right);
tty_column = add_column("TTY"_short_string, Alignment::Left);
cmd_column = add_column("CMD"_short_string, Alignment::Left);
@@ -133,7 +135,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(header.try_ensure_capacity(columns.size()));
for (auto& column : columns)
header.unchecked_append(column.title);
- rows.append(move(header));
+ rows.unchecked_append(move(header));
for (auto const& process : processes) {
auto tty = TRY(String::from_deprecated_string(process.tty));
@@ -165,7 +167,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (cmd_column != -1)
row[cmd_column] = TRY(String::from_deprecated_string(process.name));
- TRY(rows.try_append(move(row)));
+ rows.unchecked_append(move(row));
}
for (size_t i = 0; i < columns.size(); i++) {