diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2022-01-28 21:22:13 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-28 23:31:00 +0100 |
commit | 7d11edbe173f49e1559ebb9bea8442bedd00fc0e (patch) | |
tree | ecef929f166d3d56ce8f6c6b0f297f829f21cfd9 /Userland/Services | |
parent | c1184c1fde517993e3f719c7e5aa636197cb2dfc (diff) | |
download | serenity-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/Services')
-rw-r--r-- | Userland/Services/Clipboard/Storage.cpp | 6 | ||||
-rw-r--r-- | Userland/Services/Taskbar/WindowList.cpp | 6 |
2 files changed, 4 insertions, 8 deletions
diff --git a/Userland/Services/Clipboard/Storage.cpp b/Userland/Services/Clipboard/Storage.cpp index f89f300af3..5bc7f48aaa 100644 --- a/Userland/Services/Clipboard/Storage.cpp +++ b/Userland/Services/Clipboard/Storage.cpp @@ -10,10 +10,8 @@ namespace Clipboard { Storage& Storage::the() { - static Storage* s_the; - if (!s_the) - s_the = new Storage; - return *s_the; + static Storage s_the; + return s_the; } Storage::Storage() diff --git a/Userland/Services/Taskbar/WindowList.cpp b/Userland/Services/Taskbar/WindowList.cpp index eb11240b5d..0af99bf5b0 100644 --- a/Userland/Services/Taskbar/WindowList.cpp +++ b/Userland/Services/Taskbar/WindowList.cpp @@ -8,10 +8,8 @@ WindowList& WindowList::the() { - static WindowList* s_the; - if (!s_the) - s_the = new WindowList; - return *s_the; + static WindowList s_the; + return s_the; } Window* WindowList::find_parent(const Window& window) |