Kernel: Make OpenFileDescritorSet::open take rvalue

This gets rid of some implicit allocations from copy constructors
This commit is contained in:
Bananymous 2024-08-28 16:36:10 +03:00
parent 5f66ef34dd
commit d20752c318
3 changed files with 8 additions and 7 deletions

View File

@ -22,7 +22,7 @@ namespace Kernel
BAN::ErrorOr<void> clone_from(const OpenFileDescriptorSet&);
BAN::ErrorOr<int> open(VirtualFileSystem::File, int flags);
BAN::ErrorOr<int> open(VirtualFileSystem::File&&, int flags);
BAN::ErrorOr<int> open(BAN::StringView absolute_path, int flags);
BAN::ErrorOr<int> socket(int domain, int type, int protocol);

View File

@ -58,7 +58,7 @@ namespace Kernel
return {};
}
BAN::ErrorOr<int> OpenFileDescriptorSet::open(VirtualFileSystem::File file, int flags)
BAN::ErrorOr<int> OpenFileDescriptorSet::open(VirtualFileSystem::File&& file, int flags)
{
ASSERT(file.inode);

View File

@ -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<TTY*>(file.inode.ptr());
if (!(flags & O_NOCTTY) && inode->is_tty() && is_session_leader() && !m_controlling_terminal)
m_controlling_terminal = static_cast<TTY*>(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();