From d20752c3184965b08b0affa6c4265bd9d32accf5 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 28 Aug 2024 16:36:10 +0300 Subject: [PATCH] Kernel: Make OpenFileDescritorSet::open take rvalue This gets rid of some implicit allocations from copy constructors --- kernel/include/kernel/OpenFileDescriptorSet.h | 2 +- kernel/kernel/OpenFileDescriptorSet.cpp | 2 +- kernel/kernel/Process.cpp | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/kernel/include/kernel/OpenFileDescriptorSet.h b/kernel/include/kernel/OpenFileDescriptorSet.h index 2060d257..7fb6b599 100644 --- a/kernel/include/kernel/OpenFileDescriptorSet.h +++ b/kernel/include/kernel/OpenFileDescriptorSet.h @@ -22,7 +22,7 @@ namespace Kernel BAN::ErrorOr clone_from(const OpenFileDescriptorSet&); - BAN::ErrorOr open(VirtualFileSystem::File, int flags); + BAN::ErrorOr open(VirtualFileSystem::File&&, int flags); BAN::ErrorOr open(BAN::StringView absolute_path, int flags); BAN::ErrorOr socket(int domain, int type, int protocol); diff --git a/kernel/kernel/OpenFileDescriptorSet.cpp b/kernel/kernel/OpenFileDescriptorSet.cpp index 521b1637..403ed184 100644 --- a/kernel/kernel/OpenFileDescriptorSet.cpp +++ b/kernel/kernel/OpenFileDescriptorSet.cpp @@ -58,7 +58,7 @@ namespace Kernel return {}; } - BAN::ErrorOr OpenFileDescriptorSet::open(VirtualFileSystem::File file, int flags) + BAN::ErrorOr OpenFileDescriptorSet::open(VirtualFileSystem::File&& file, int flags) { ASSERT(file.inode); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 547aba73..0a9679b6 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -910,13 +910,14 @@ namespace Kernel file = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, absolute_path, flags)); } - ASSERT(file.inode); + auto inode = file.inode; + ASSERT(inode); - int fd = TRY(m_open_file_descriptors.open(file, flags)); + int fd = TRY(m_open_file_descriptors.open(BAN::move(file), flags)); // Open controlling terminal - if (!(flags & O_NOCTTY) && file.inode->is_tty() && is_session_leader() && !m_controlling_terminal) - m_controlling_terminal = static_cast(file.inode.ptr()); + if (!(flags & O_NOCTTY) && inode->is_tty() && is_session_leader() && !m_controlling_terminal) + m_controlling_terminal = static_cast(inode.ptr()); return fd; } @@ -1775,7 +1776,7 @@ namespace Kernel LockGuard _(m_process_lock); - int pts_master_fd = TRY(m_open_file_descriptors.open(file, flags)); + int pts_master_fd = TRY(m_open_file_descriptors.open(BAN::move(file), flags)); if (!(flags & O_NOCTTY) && is_session_leader() && !m_controlling_terminal) m_controlling_terminal = (TTY*)pts_slave.ptr();