From d6de0613f59d64610f38eea8c9acf4643dcea2ab Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 28 Aug 2021 02:38:23 -0600 Subject: [PATCH] LibCore: Store ObjectRegistration names as StringViews We don't need to be allocating Strings for these names during static initialization. The C-string literals will be stored in the .rodata ELF section, so they're not going anywhere. We can just wrap the .rodata storage for the class names in StringViews and use those in Object registration and lookup APIs. --- Userland/Libraries/LibCore/Object.cpp | 10 +++++----- Userland/Libraries/LibCore/Object.h | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibCore/Object.cpp b/Userland/Libraries/LibCore/Object.cpp index 706bf3c95f..9009d4c850 100644 --- a/Userland/Libraries/LibCore/Object.cpp +++ b/Userland/Libraries/LibCore/Object.cpp @@ -250,15 +250,15 @@ void Object::set_event_filter(Function filter) m_event_filter = move(filter); } -static HashMap& object_classes() +static HashMap& object_classes() { - static HashMap* map; + static HashMap* map; if (!map) - map = new HashMap; + map = new HashMap; return *map; } -ObjectClassRegistration::ObjectClassRegistration(const String& class_name, Function()> factory, ObjectClassRegistration* parent_class) +ObjectClassRegistration::ObjectClassRegistration(StringView class_name, Function()> factory, ObjectClassRegistration* parent_class) : m_class_name(class_name) , m_factory(move(factory)) , m_parent_class(parent_class) @@ -286,7 +286,7 @@ void ObjectClassRegistration::for_each(Function()> factory, ObjectClassRegistration* parent_class = nullptr); + ObjectClassRegistration(StringView class_name, Function()> factory, ObjectClassRegistration* parent_class = nullptr); ~ObjectClassRegistration(); String class_name() const { return m_class_name; } @@ -41,10 +41,10 @@ public: bool is_derived_from(const ObjectClassRegistration& base_class) const; static void for_each(Function); - static const ObjectClassRegistration* find(const String& class_name); + static const ObjectClassRegistration* find(StringView class_name); private: - String m_class_name; + StringView m_class_name; Function()> m_factory; ObjectClassRegistration* m_parent_class { nullptr }; };