From 4cbe348a0fd7209846d5f8c68c5436ef9fedd526 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 28 Aug 2021 22:24:53 +0200 Subject: [PATCH] Kernel/Ext2FS: Avoid temporary String allocation during inode creation Make sure we pass the StringView we get all the way through so it never turns into a heap-allocated String. :^) --- Kernel/FileSystem/Ext2FileSystem.cpp | 4 ++-- Kernel/FileSystem/Ext2FileSystem.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 4df65b7187..a961a6869b 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -1539,7 +1539,7 @@ KResult Ext2FS::set_block_allocation_state(BlockIndex block_index, bool new_stat return update_bitmap_block(bgd.bg_block_bitmap, bit_index, new_state, m_super_block.s_free_blocks_count, bgd.bg_free_blocks_count); } -KResult Ext2FS::create_directory(Ext2FSInode& parent_inode, const String& name, mode_t mode, UserID uid, GroupID gid) +KResult Ext2FS::create_directory(Ext2FSInode& parent_inode, StringView name, mode_t mode, UserID uid, GroupID gid) { MutexLocker locker(m_lock); VERIFY(is_directory(mode)); @@ -1569,7 +1569,7 @@ KResult Ext2FS::create_directory(Ext2FSInode& parent_inode, const String& name, return KSuccess; } -KResultOr> Ext2FS::create_inode(Ext2FSInode& parent_inode, const String& name, mode_t mode, dev_t dev, UserID uid, GroupID gid) +KResultOr> Ext2FS::create_inode(Ext2FSInode& parent_inode, StringView name, mode_t mode, dev_t dev, UserID uid, GroupID gid) { if (name.length() > EXT2_NAME_LEN) return ENAMETOOLONG; diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h index e116fbbc94..c73b14230e 100644 --- a/Kernel/FileSystem/Ext2FileSystem.h +++ b/Kernel/FileSystem/Ext2FileSystem.h @@ -130,8 +130,8 @@ private: virtual StringView class_name() const override { return "Ext2FS"sv; } virtual Ext2FSInode& root_inode() override; RefPtr get_inode(InodeIdentifier) const; - KResultOr> create_inode(Ext2FSInode& parent_inode, const String& name, mode_t, dev_t, UserID, GroupID); - KResult create_directory(Ext2FSInode& parent_inode, const String& name, mode_t, UserID, GroupID); + KResultOr> create_inode(Ext2FSInode& parent_inode, StringView name, mode_t, dev_t, UserID, GroupID); + KResult create_directory(Ext2FSInode& parent_inode, StringView name, mode_t, UserID, GroupID); virtual void flush_writes() override; BlockIndex first_block_index() const;