1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:08:12 +00:00

Kernel: Use KString instead of String in Ext2FSInode's lookup cache

This commit is contained in:
Idan Horowitz 2022-01-21 12:35:48 +02:00 committed by Andreas Kling
parent 7356110033
commit 77a81f5eed
2 changed files with 9 additions and 7 deletions

View file

@ -1174,7 +1174,8 @@ ErrorOr<void> Ext2FSInode::add_child(Inode& child, StringView name, mode_t mode)
TRY(write_directory(entries)); TRY(write_directory(entries));
TRY(populate_lookup_cache()); TRY(populate_lookup_cache());
TRY(m_lookup_cache.try_set(name, child.index())); auto cache_entry_name = TRY(KString::try_create(name));
TRY(m_lookup_cache.try_set(move(cache_entry_name), child.index()));
did_add_child(child.identifier(), name); did_add_child(child.identifier(), name);
return {}; return {};
} }
@ -1187,7 +1188,7 @@ ErrorOr<void> Ext2FSInode::remove_child(StringView name)
TRY(populate_lookup_cache()); TRY(populate_lookup_cache());
auto it = m_lookup_cache.find(name); auto it = m_lookup_cache.find(name.hash(), [&](auto& entry) { return entry.key->view() == name; });
if (it == m_lookup_cache.end()) if (it == m_lookup_cache.end())
return ENOENT; return ENOENT;
auto child_inode_index = (*it).value; auto child_inode_index = (*it).value;
@ -1205,7 +1206,7 @@ ErrorOr<void> Ext2FSInode::remove_child(StringView name)
TRY(write_directory(entries)); TRY(write_directory(entries));
m_lookup_cache.remove(name); m_lookup_cache.remove(it);
auto child_inode = TRY(fs().get_inode(child_id)); auto child_inode = TRY(fs().get_inode(child_id));
TRY(child_inode->decrement_link_count()); TRY(child_inode->decrement_link_count());
@ -1527,10 +1528,11 @@ ErrorOr<void> Ext2FSInode::populate_lookup_cache() const
MutexLocker locker(m_inode_lock); MutexLocker locker(m_inode_lock);
if (!m_lookup_cache.is_empty()) if (!m_lookup_cache.is_empty())
return {}; return {};
HashMap<String, InodeIndex> children; HashMap<NonnullOwnPtr<KString>, InodeIndex> children;
TRY(traverse_as_directory([&children](auto& entry) -> ErrorOr<void> { TRY(traverse_as_directory([&children](auto& entry) -> ErrorOr<void> {
TRY(children.try_set(entry.name, entry.inode.index())); auto entry_name = TRY(KString::try_create(entry.name));
TRY(children.try_set(move(entry_name), entry.inode.index()));
return {}; return {};
})); }));
@ -1548,7 +1550,7 @@ ErrorOr<NonnullRefPtr<Inode>> Ext2FSInode::lookup(StringView name)
InodeIndex inode_index; InodeIndex inode_index;
{ {
MutexLocker locker(m_inode_lock); MutexLocker locker(m_inode_lock);
auto it = m_lookup_cache.find(name.hash(), [&](auto& entry) { return entry.key == name; }); auto it = m_lookup_cache.find(name.hash(), [&](auto& entry) { return entry.key->view() == name; });
if (it == m_lookup_cache.end()) { if (it == m_lookup_cache.end()) {
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): '{}' not found", identifier(), name); dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): '{}' not found", identifier(), name);
return ENOENT; return ENOENT;

View file

@ -73,7 +73,7 @@ private:
Ext2FSInode(Ext2FS&, InodeIndex); Ext2FSInode(Ext2FS&, InodeIndex);
mutable Vector<BlockBasedFileSystem::BlockIndex> m_block_list; mutable Vector<BlockBasedFileSystem::BlockIndex> m_block_list;
mutable HashMap<String, InodeIndex> m_lookup_cache; mutable HashMap<NonnullOwnPtr<KString>, InodeIndex> m_lookup_cache;
ext2_inode m_raw_inode {}; ext2_inode m_raw_inode {};
}; };