From 7d11edbe173f49e1559ebb9bea8442bedd00fc0e Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Fri, 28 Jan 2022 21:22:13 +0100 Subject: 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. --- Userland/Services/Clipboard/Storage.cpp | 6 ++---- Userland/Services/Taskbar/WindowList.cpp | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'Userland/Services') 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) -- cgit v1.2.3