From b020a5e7ce643663162c319cf91660a2c3039a0f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 24 Aug 2019 22:01:17 +0200 Subject: [PATCH] Kernel: Don't create a String every time we look up a Custody by name --- Kernel/FileSystem/Custody.cpp | 11 ++++------- Kernel/FileSystem/Custody.h | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Kernel/FileSystem/Custody.cpp b/Kernel/FileSystem/Custody.cpp index 57ae28d6e17..519c8414d40 100644 --- a/Kernel/FileSystem/Custody.cpp +++ b/Kernel/FileSystem/Custody.cpp @@ -12,7 +12,7 @@ static Lockable>& all_custodies() return *list; } -Custody* Custody::get_if_cached(Custody* parent, const String& name) +Custody* Custody::get_if_cached(Custody* parent, const StringView& name) { LOCKER(all_custodies().lock()); for (auto& custody : all_custodies().resource()) { @@ -26,14 +26,11 @@ Custody* Custody::get_if_cached(Custody* parent, const String& name) return nullptr; } -NonnullRefPtr Custody::get_or_create(Custody* parent, const String& name, Inode& inode) +NonnullRefPtr Custody::get_or_create(Custody* parent, const StringView& name, Inode& inode) { if (RefPtr cached_custody = get_if_cached(parent, name)) { if (&cached_custody->inode() != &inode) { - dbgprintf("WTF! cached custody for name '%s' has inode=%s, new inode=%s\n", - name.characters(), - cached_custody->inode().identifier().to_string().characters(), - inode.identifier().to_string().characters()); + dbg() << "WTF! Cached custody for name '" << name << "' has inode=" << cached_custody->inode().identifier() << ", new inode=" << inode.identifier(); } ASSERT(&cached_custody->inode() == &inode); return *cached_custody; @@ -41,7 +38,7 @@ NonnullRefPtr Custody::get_or_create(Custody* parent, const String& nam return create(parent, name, inode); } -Custody::Custody(Custody* parent, const String& name, Inode& inode) +Custody::Custody(Custody* parent, const StringView& name, Inode& inode) : m_parent(parent) , m_name(name) , m_inode(inode) diff --git a/Kernel/FileSystem/Custody.h b/Kernel/FileSystem/Custody.h index 746b484a05a..23b8667219d 100644 --- a/Kernel/FileSystem/Custody.h +++ b/Kernel/FileSystem/Custody.h @@ -14,9 +14,9 @@ class VFS; class Custody : public RefCounted , public InlineLinkedListNode { public: - static Custody* get_if_cached(Custody* parent, const String& name); - static NonnullRefPtr get_or_create(Custody* parent, const String& name, Inode&); - static NonnullRefPtr create(Custody* parent, const String& name, Inode& inode) + static Custody* get_if_cached(Custody* parent, const StringView& name); + static NonnullRefPtr get_or_create(Custody* parent, const StringView& name, Inode&); + static NonnullRefPtr create(Custody* parent, const StringView& name, Inode& inode) { return adopt(*new Custody(parent, name, inode)); } @@ -42,7 +42,7 @@ public: Custody* m_prev { nullptr }; private: - Custody(Custody* parent, const String& name, Inode&); + Custody(Custody* parent, const StringView& name, Inode&); RefPtr m_parent; String m_name;