From 942a5afd23ff41803118482551e7c961cb37281f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 16 Apr 2021 19:59:31 +0200 Subject: [PATCH] LibCore: Don't needlessly use StringView in Core::Object APIs Taking a StringView parameter that gets immediately converted to a String anyway is silly. Just take a String directly instead. This pattern is the main reason we have the "StringView internal StringImpl pointer" optimization, and I suspect that we can throw that whole thing out if we make a couple more patches like this. --- Userland/Libraries/LibCore/Object.cpp | 4 ++-- Userland/Libraries/LibCore/Object.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibCore/Object.cpp b/Userland/Libraries/LibCore/Object.cpp index 13c57baebf..3711653547 100644 --- a/Userland/Libraries/LibCore/Object.cpp +++ b/Userland/Libraries/LibCore/Object.cpp @@ -195,7 +195,7 @@ void Object::save_to(JsonObject& json) } } -JsonValue Object::property(const StringView& name) const +JsonValue Object::property(String const& name) const { auto it = m_properties.find(name); if (it == m_properties.end()) @@ -203,7 +203,7 @@ JsonValue Object::property(const StringView& name) const return it->value->get(); } -bool Object::set_property(const StringView& name, const JsonValue& value) +bool Object::set_property(String const& name, JsonValue const& value) { auto it = m_properties.find(name); if (it == m_properties.end()) diff --git a/Userland/Libraries/LibCore/Object.h b/Userland/Libraries/LibCore/Object.h index 21980c8b0e..dd76f2592a 100644 --- a/Userland/Libraries/LibCore/Object.h +++ b/Userland/Libraries/LibCore/Object.h @@ -75,7 +75,7 @@ public: virtual const char* class_name() const = 0; const String& name() const { return m_name; } - void set_name(const StringView& name) { m_name = name; } + void set_name(String name) { m_name = move(name); } NonnullRefPtrVector& children() { return m_children; } const NonnullRefPtrVector& children() const { return m_children; } @@ -120,8 +120,8 @@ public: void save_to(JsonObject&); - bool set_property(const StringView& name, const JsonValue& value); - JsonValue property(const StringView& name) const; + bool set_property(String const& name, const JsonValue& value); + JsonValue property(String const& name) const; const HashMap>& properties() const { return m_properties; } static IntrusiveList, &Object::m_all_objects_list_node>& all_objects();