From 5ab044beae2d5c86771c2468249157e7d5b60c43 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 2 Oct 2019 13:37:44 +0200 Subject: [PATCH] Ext2FS: Make Ext2FSInode::is_directory() fast This patch overloads Inode::is_directory() with a faster version that doesn't require instantiating the whole InodeMetadata. If you have an Ext2FSInode&, calling is_directory() should be instant since we can just look directly at the raw inode bits. --- Kernel/FileSystem/Ext2FileSystem.cpp | 2 +- Kernel/FileSystem/Ext2FileSystem.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index b21414a117..ffa5dbb7ea 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -802,7 +802,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi bool Ext2FSInode::traverse_as_directory(Function callback) const { LOCKER(m_lock); - ASSERT(metadata().is_directory()); + ASSERT(is_directory()); #ifdef EXT2_DEBUG kprintf("Ext2Inode::traverse_as_directory: inode=%u:\n", index()); diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h index 60d6950e82..e15803dff2 100644 --- a/Kernel/FileSystem/Ext2FileSystem.h +++ b/Kernel/FileSystem/Ext2FileSystem.h @@ -19,6 +19,7 @@ public: size_t size() const { return m_raw_inode.i_size; } bool is_symlink() const { return ::is_symlink(m_raw_inode.i_mode); } + bool is_directory() const { return ::is_directory(m_raw_inode.i_mode); } // ^Inode (RefCounted magic) virtual void one_ref_left() override;