mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:18:13 +00:00
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.
This commit is contained in:
parent
ea364af965
commit
d6de0613f5
2 changed files with 8 additions and 8 deletions
|
@ -250,15 +250,15 @@ void Object::set_event_filter(Function<bool(Core::Event&)> filter)
|
|||
m_event_filter = move(filter);
|
||||
}
|
||||
|
||||
static HashMap<String, ObjectClassRegistration*>& object_classes()
|
||||
static HashMap<StringView, ObjectClassRegistration*>& object_classes()
|
||||
{
|
||||
static HashMap<String, ObjectClassRegistration*>* map;
|
||||
static HashMap<StringView, ObjectClassRegistration*>* map;
|
||||
if (!map)
|
||||
map = new HashMap<String, ObjectClassRegistration*>;
|
||||
map = new HashMap<StringView, ObjectClassRegistration*>;
|
||||
return *map;
|
||||
}
|
||||
|
||||
ObjectClassRegistration::ObjectClassRegistration(const String& class_name, Function<NonnullRefPtr<Object>()> factory, ObjectClassRegistration* parent_class)
|
||||
ObjectClassRegistration::ObjectClassRegistration(StringView class_name, Function<NonnullRefPtr<Object>()> 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<void(const ObjectClassRegistrati
|
|||
}
|
||||
}
|
||||
|
||||
const ObjectClassRegistration* ObjectClassRegistration::find(const String& class_name)
|
||||
const ObjectClassRegistration* ObjectClassRegistration::find(StringView class_name)
|
||||
{
|
||||
return object_classes().get(class_name).value_or(nullptr);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue