diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-28 11:21:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-28 11:21:00 +0200 |
commit | 9a827ad3da16aafd8ef47efefd5b18ca2fb1f07b (patch) | |
tree | b28a529d11144dda1daaa757a3340852c4aeefbc /Kernel/FileSystem | |
parent | fc9ce229819c232e8960fe14e14157ab2befd43c (diff) | |
download | serenity-9a827ad3da16aafd8ef47efefd5b18ca2fb1f07b.zip |
Kernel: Use a KString for Custody::m_name
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/Custody.cpp | 17 | ||||
-rw-r--r-- | Kernel/FileSystem/Custody.h | 16 |
2 files changed, 19 insertions, 14 deletions
diff --git a/Kernel/FileSystem/Custody.cpp b/Kernel/FileSystem/Custody.cpp index c797c5aaee..ed621a3f1a 100644 --- a/Kernel/FileSystem/Custody.cpp +++ b/Kernel/FileSystem/Custody.cpp @@ -12,9 +12,20 @@ namespace Kernel { -Custody::Custody(Custody* parent, const StringView& name, Inode& inode, int mount_flags) +KResultOr<NonnullRefPtr<Custody>> Custody::create(Custody* parent, StringView name, Inode& inode, int mount_flags) +{ + auto name_kstring = KString::try_create(name); + if (!name_kstring) + return ENOMEM; + auto custody = adopt_ref_if_nonnull(new Custody(parent, name_kstring.release_nonnull(), inode, mount_flags)); + if (!custody) + return ENOMEM; + return custody.release_nonnull(); +} + +Custody::Custody(Custody* parent, NonnullOwnPtr<KString> name, Inode& inode, int mount_flags) : m_parent(parent) - , m_name(name) + , m_name(move(name)) , m_inode(inode) , m_mount_flags(mount_flags) { @@ -34,7 +45,7 @@ String Custody::absolute_path() const StringBuilder builder; for (int i = custody_chain.size() - 2; i >= 0; --i) { builder.append('/'); - builder.append(custody_chain[i]->name().characters()); + builder.append(custody_chain[i]->name()); } return builder.to_string(); } diff --git a/Kernel/FileSystem/Custody.h b/Kernel/FileSystem/Custody.h index 34bbba5137..f324693e1b 100644 --- a/Kernel/FileSystem/Custody.h +++ b/Kernel/FileSystem/Custody.h @@ -12,6 +12,7 @@ #include <Kernel/Forward.h> #include <Kernel/Heap/SlabAllocator.h> #include <Kernel/KResult.h> +#include <Kernel/KString.h> namespace Kernel { @@ -20,14 +21,7 @@ namespace Kernel { class Custody : public RefCounted<Custody> { MAKE_SLAB_ALLOCATED(Custody) public: - static KResultOr<NonnullRefPtr<Custody>> create(Custody* parent, const StringView& name, Inode& inode, int mount_flags) - { - auto custody = adopt_ref_if_nonnull(new Custody(parent, name, inode, mount_flags)); - if (!custody) - return ENOMEM; - - return custody.release_nonnull(); - } + static KResultOr<NonnullRefPtr<Custody>> create(Custody* parent, StringView name, Inode& inode, int mount_flags); ~Custody(); @@ -35,17 +29,17 @@ public: const Custody* parent() const { return m_parent.ptr(); } Inode& inode() { return *m_inode; } const Inode& inode() const { return *m_inode; } - const String& name() const { return m_name; } + StringView name() const { return m_name->view(); } String absolute_path() const; int mount_flags() const { return m_mount_flags; } bool is_readonly() const; private: - Custody(Custody* parent, const StringView& name, Inode&, int mount_flags); + Custody(Custody* parent, NonnullOwnPtr<KString> name, Inode&, int mount_flags); RefPtr<Custody> m_parent; - String m_name; + NonnullOwnPtr<KString> m_name; NonnullRefPtr<Inode> m_inode; int m_mount_flags { 0 }; }; |