summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/Object.cpp
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2022-01-28 21:22:13 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-28 23:31:00 +0100
commit7d11edbe173f49e1559ebb9bea8442bedd00fc0e (patch)
treeecef929f166d3d56ce8f6c6b0f297f829f21cfd9 /Userland/Libraries/LibCore/Object.cpp
parentc1184c1fde517993e3f719c7e5aa636197cb2dfc (diff)
downloadserenity-7d11edbe173f49e1559ebb9bea8442bedd00fc0e.zip
Userland: Fix unnecessary heap allocation of singleton objects
In order to avoid having multiple instances, we were keeping a pointer to these singleton objects and only allocating them when it was null. We have `__cxa_guard_{acquire,release}` in the userland, so there's no need to do this dance, as the compiler will ensure that the constructors are only called once.
Diffstat (limited to 'Userland/Libraries/LibCore/Object.cpp')
-rw-r--r--Userland/Libraries/LibCore/Object.cpp6
1 files changed, 2 insertions, 4 deletions
diff --git a/Userland/Libraries/LibCore/Object.cpp b/Userland/Libraries/LibCore/Object.cpp
index 19dd4134b4..66c47b0bf5 100644
--- a/Userland/Libraries/LibCore/Object.cpp
+++ b/Userland/Libraries/LibCore/Object.cpp
@@ -258,10 +258,8 @@ void Object::set_event_filter(Function<bool(Core::Event&)> filter)
static HashMap<StringView, ObjectClassRegistration*>& object_classes()
{
- static HashMap<StringView, ObjectClassRegistration*>* map;
- if (!map)
- map = new HashMap<StringView, ObjectClassRegistration*>;
- return *map;
+ static HashMap<StringView, ObjectClassRegistration*> s_map;
+ return s_map;
}
ObjectClassRegistration::ObjectClassRegistration(StringView class_name, Function<RefPtr<Object>()> factory, ObjectClassRegistration* parent_class)