diff options
author | Andreas Kling <kling@serenityos.org> | 2022-01-28 15:05:59 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-28 23:41:18 +0100 |
commit | b27b22a68c095daaa2a7f32a4b6cac3659cbb10e (patch) | |
tree | 50eb4c0b06c20472657e7e522e8a9dd8ceb800fa /Kernel/Syscalls/poll.cpp | |
parent | a12e19c0152e1236a0e26a0b82a2a8c10ba8a55b (diff) | |
download | serenity-b27b22a68c095daaa2a7f32a4b6cac3659cbb10e.zip |
Kernel: Allocate entire SelectBlocker::FDVector at once
Use try_ensure_capacity() + unchecked_append() instead of repeatedly
doing try_append().
Diffstat (limited to 'Kernel/Syscalls/poll.cpp')
-rw-r--r-- | Kernel/Syscalls/poll.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Kernel/Syscalls/poll.cpp b/Kernel/Syscalls/poll.cpp index 8c63ee51c2..3619b7bb10 100644 --- a/Kernel/Syscalls/poll.cpp +++ b/Kernel/Syscalls/poll.cpp @@ -45,6 +45,8 @@ ErrorOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> use } Thread::SelectBlocker::FDVector fds_info; + TRY(fds_info.try_ensure_capacity(params.nfds)); + for (size_t i = 0; i < params.nfds; i++) { auto& pfd = fds_copy[i]; auto description = TRY(fds().open_file_description(pfd.fd)); @@ -57,7 +59,7 @@ ErrorOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> use block_flags |= BlockFlags::ReadPriority; if (pfd.events & POLLWRBAND) block_flags |= BlockFlags::WritePriority; - TRY(fds_info.try_append({ move(description), block_flags })); + fds_info.unchecked_append({ move(description), block_flags }); } auto* current_thread = Thread::current(); |