From b6efd66d563a2d378e6b40a313c1b50808f78f0d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 15 Sep 2021 21:09:47 +0200 Subject: [PATCH] Kernel: Use move semantics in sys$sendfd() Avoid an unnecessary NonnullRefPtr copy. --- Kernel/Net/LocalSocket.cpp | 2 +- Kernel/Net/LocalSocket.h | 2 +- Kernel/Syscalls/sendfd.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index a6c7fb976e..f5dc0cc9f4 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -466,7 +466,7 @@ NonnullRefPtrVector& LocalSocket::sendfd_queue_for(const Op VERIFY_NOT_REACHED(); } -KResult LocalSocket::sendfd(const OpenFileDescription& socket_description, OpenFileDescription& passing_description) +KResult LocalSocket::sendfd(OpenFileDescription const& socket_description, NonnullRefPtr passing_description) { MutexLocker locker(mutex()); auto role = this->role(socket_description); diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h index 96e0322f6b..f1327944e0 100644 --- a/Kernel/Net/LocalSocket.h +++ b/Kernel/Net/LocalSocket.h @@ -26,7 +26,7 @@ public: static KResultOr try_create_connected_pair(int type); virtual ~LocalSocket() override; - KResult sendfd(const OpenFileDescription& socket_description, OpenFileDescription& passing_description); + KResult sendfd(OpenFileDescription const& socket_description, NonnullRefPtr passing_description); KResultOr> recvfd(const OpenFileDescription& socket_description); static void for_each(Function); diff --git a/Kernel/Syscalls/sendfd.cpp b/Kernel/Syscalls/sendfd.cpp index ea77b41bc9..99b8cab240 100644 --- a/Kernel/Syscalls/sendfd.cpp +++ b/Kernel/Syscalls/sendfd.cpp @@ -23,9 +23,9 @@ KResultOr Process::sys$sendfd(int sockfd, int fd) if (!socket.is_connected()) return ENOTCONN; - auto passing_descriptor = TRY(fds().open_file_description(fd)); + auto passing_description = TRY(fds().open_file_description(fd)); auto& local_socket = static_cast(socket); - return local_socket.sendfd(*socket_description, *passing_descriptor); + return local_socket.sendfd(*socket_description, move(passing_description)); } KResultOr Process::sys$recvfd(int sockfd, int options)