From 1815a913c3b8dd7eaf90a919985f5f71f487e881 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 15 Dec 2024 20:47:40 +0200 Subject: [PATCH] Kernel: Remove unnecessary hash map lookups --- kernel/kernel/FS/Ext2/FileSystem.cpp | 5 +++-- kernel/kernel/FS/Ext2/Inode.cpp | 5 +++-- kernel/kernel/FS/TmpFS/FileSystem.cpp | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/kernel/FS/Ext2/FileSystem.cpp b/kernel/kernel/FS/Ext2/FileSystem.cpp index a0cd180681..0495d49625 100644 --- a/kernel/kernel/FS/Ext2/FileSystem.cpp +++ b/kernel/kernel/FS/Ext2/FileSystem.cpp @@ -295,8 +295,9 @@ namespace Kernel TRY(sync_superblock()); // remove inode from cache - if (m_inode_cache.contains(ino)) - m_inode_cache.remove(ino); + auto it = m_inode_cache.find(ino); + if (it != m_inode_cache.end()) + m_inode_cache.remove(it); return {}; } diff --git a/kernel/kernel/FS/Ext2/Inode.cpp b/kernel/kernel/FS/Ext2/Inode.cpp index 87f42133b4..91c900df9a 100644 --- a/kernel/kernel/FS/Ext2/Inode.cpp +++ b/kernel/kernel/FS/Ext2/Inode.cpp @@ -24,8 +24,9 @@ namespace Kernel BAN::ErrorOr> Ext2Inode::create(Ext2FS& fs, uint32_t inode_ino) { - if (fs.inode_cache().contains(inode_ino)) - return fs.inode_cache()[inode_ino]; + auto it = fs.inode_cache().find(inode_ino); + if (it != fs.inode_cache().end()) + return it->value; auto inode_location = TRY(fs.locate_inode(inode_ino)); diff --git a/kernel/kernel/FS/TmpFS/FileSystem.cpp b/kernel/kernel/FS/TmpFS/FileSystem.cpp index 7de9ee0bb0..c78eac8d0a 100644 --- a/kernel/kernel/FS/TmpFS/FileSystem.cpp +++ b/kernel/kernel/FS/TmpFS/FileSystem.cpp @@ -68,8 +68,9 @@ namespace Kernel { LockGuard _(m_mutex); - if (m_inode_cache.contains(ino)) - return m_inode_cache[ino]; + auto it = m_inode_cache.find(ino); + if (it != m_inode_cache.end()) + return it->value; TmpInodeInfo inode_info;