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
Notes: sideshowbarker 2024-07-17 20:31:41 +09:00
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(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);
return {};
}
@ -1187,7 +1188,7 @@ ErrorOr<void> Ext2FSInode::remove_child(StringView name)
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())
return ENOENT;
auto child_inode_index = (*it).value;
@ -1205,7 +1206,7 @@ ErrorOr<void> Ext2FSInode::remove_child(StringView name)
TRY(write_directory(entries));
m_lookup_cache.remove(name);
m_lookup_cache.remove(it);
auto child_inode = TRY(fs().get_inode(child_id));
TRY(child_inode->decrement_link_count());
@ -1527,10 +1528,11 @@ ErrorOr<void> Ext2FSInode::populate_lookup_cache() const
MutexLocker locker(m_inode_lock);
if (!m_lookup_cache.is_empty())
return {};
HashMap<String, InodeIndex> children;
HashMap<NonnullOwnPtr<KString>, InodeIndex> children;
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 {};
}));
@ -1548,7 +1550,7 @@ ErrorOr<NonnullRefPtr<Inode>> Ext2FSInode::lookup(StringView name)
InodeIndex inode_index;
{
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()) {
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): '{}' not found", identifier(), name);
return ENOENT;

View file

@ -73,7 +73,7 @@ private:
Ext2FSInode(Ext2FS&, InodeIndex);
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 {};
};