1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

Kernel: Don't create a String every time we look up a Custody by name

This commit is contained in:
Andreas Kling 2019-08-24 22:01:17 +02:00
parent a00419ed77
commit b020a5e7ce
2 changed files with 8 additions and 11 deletions

View file

@ -12,7 +12,7 @@ static Lockable<InlineLinkedList<Custody>>& all_custodies()
return *list; 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()); LOCKER(all_custodies().lock());
for (auto& custody : all_custodies().resource()) { for (auto& custody : all_custodies().resource()) {
@ -26,14 +26,11 @@ Custody* Custody::get_if_cached(Custody* parent, const String& name)
return nullptr; return nullptr;
} }
NonnullRefPtr<Custody> Custody::get_or_create(Custody* parent, const String& name, Inode& inode) NonnullRefPtr<Custody> Custody::get_or_create(Custody* parent, const StringView& name, Inode& inode)
{ {
if (RefPtr<Custody> cached_custody = get_if_cached(parent, name)) { if (RefPtr<Custody> cached_custody = get_if_cached(parent, name)) {
if (&cached_custody->inode() != &inode) { if (&cached_custody->inode() != &inode) {
dbgprintf("WTF! cached custody for name '%s' has inode=%s, new inode=%s\n", dbg() << "WTF! Cached custody for name '" << name << "' has inode=" << cached_custody->inode().identifier() << ", new inode=" << inode.identifier();
name.characters(),
cached_custody->inode().identifier().to_string().characters(),
inode.identifier().to_string().characters());
} }
ASSERT(&cached_custody->inode() == &inode); ASSERT(&cached_custody->inode() == &inode);
return *cached_custody; return *cached_custody;
@ -41,7 +38,7 @@ NonnullRefPtr<Custody> Custody::get_or_create(Custody* parent, const String& nam
return create(parent, name, inode); 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_parent(parent)
, m_name(name) , m_name(name)
, m_inode(inode) , m_inode(inode)

View file

@ -14,9 +14,9 @@ class VFS;
class Custody : public RefCounted<Custody> class Custody : public RefCounted<Custody>
, public InlineLinkedListNode<Custody> { , public InlineLinkedListNode<Custody> {
public: public:
static Custody* get_if_cached(Custody* parent, const String& name); static Custody* get_if_cached(Custody* parent, const StringView& name);
static NonnullRefPtr<Custody> get_or_create(Custody* parent, const String& name, Inode&); static NonnullRefPtr<Custody> get_or_create(Custody* parent, const StringView& name, Inode&);
static NonnullRefPtr<Custody> create(Custody* parent, const String& name, Inode& inode) static NonnullRefPtr<Custody> create(Custody* parent, const StringView& name, Inode& inode)
{ {
return adopt(*new Custody(parent, name, inode)); return adopt(*new Custody(parent, name, inode));
} }
@ -42,7 +42,7 @@ public:
Custody* m_prev { nullptr }; Custody* m_prev { nullptr };
private: private:
Custody(Custody* parent, const String& name, Inode&); Custody(Custody* parent, const StringView& name, Inode&);
RefPtr<Custody> m_parent; RefPtr<Custody> m_parent;
String m_name; String m_name;