mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 14:28:49 +00:00
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.
This commit is contained in:
parent
c1184c1fde
commit
7d11edbe17
Notes:
sideshowbarker
2024-07-17 20:04:47 +09:00
Author: https://github.com/BertalanD
Commit: 7d11edbe17
Pull-request: https://github.com/SerenityOS/serenity/pull/12189
9 changed files with 18 additions and 35 deletions
|
@ -258,10 +258,8 @@ void Object::set_event_filter(Function<bool(Core::Event&)> filter)
|
||||||
|
|
||||||
static HashMap<StringView, ObjectClassRegistration*>& object_classes()
|
static HashMap<StringView, ObjectClassRegistration*>& object_classes()
|
||||||
{
|
{
|
||||||
static HashMap<StringView, ObjectClassRegistration*>* map;
|
static HashMap<StringView, ObjectClassRegistration*> s_map;
|
||||||
if (!map)
|
return s_map;
|
||||||
map = new HashMap<StringView, ObjectClassRegistration*>;
|
|
||||||
return *map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectClassRegistration::ObjectClassRegistration(StringView class_name, Function<RefPtr<Object>()> factory, ObjectClassRegistration* parent_class)
|
ObjectClassRegistration::ObjectClassRegistration(StringView class_name, Function<RefPtr<Object>()> factory, ObjectClassRegistration* parent_class)
|
||||||
|
|
|
@ -44,10 +44,8 @@ void Clipboard::initialize(Badge<Application>)
|
||||||
|
|
||||||
Clipboard& Clipboard::the()
|
Clipboard& Clipboard::the()
|
||||||
{
|
{
|
||||||
static Clipboard* s_the;
|
static Clipboard s_the;
|
||||||
if (!s_the)
|
return s_the;
|
||||||
s_the = new Clipboard;
|
|
||||||
return *s_the;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Clipboard::DataAndType Clipboard::fetch_data_and_type() const
|
Clipboard::DataAndType Clipboard::fetch_data_and_type() const
|
||||||
|
|
|
@ -16,10 +16,8 @@ namespace GUI {
|
||||||
|
|
||||||
Desktop& Desktop::the()
|
Desktop& Desktop::the()
|
||||||
{
|
{
|
||||||
static Desktop* the;
|
static Desktop s_the;
|
||||||
if (!the)
|
return s_the;
|
||||||
the = new Desktop;
|
|
||||||
return *the;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Desktop::Desktop()
|
Desktop::Desktop()
|
||||||
|
|
|
@ -31,10 +31,8 @@ private:
|
||||||
|
|
||||||
static HashMap<i32, RefPtr<DisplayLinkCallback>>& callbacks()
|
static HashMap<i32, RefPtr<DisplayLinkCallback>>& callbacks()
|
||||||
{
|
{
|
||||||
static HashMap<i32, RefPtr<DisplayLinkCallback>>* map;
|
static HashMap<i32, RefPtr<DisplayLinkCallback>> s_map;
|
||||||
if (!map)
|
return s_map;
|
||||||
map = new HashMap<i32, RefPtr<DisplayLinkCallback>>;
|
|
||||||
return *map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static i32 s_next_callback_id = 1;
|
static i32 s_next_callback_id = 1;
|
||||||
|
|
|
@ -20,10 +20,8 @@ static IDAllocator s_menu_id_allocator;
|
||||||
|
|
||||||
static HashMap<int, Menu*>& all_menus()
|
static HashMap<int, Menu*>& all_menus()
|
||||||
{
|
{
|
||||||
static HashMap<int, Menu*>* map;
|
static HashMap<int, Menu*> s_map;
|
||||||
if (!map)
|
return s_map;
|
||||||
map = new HashMap<int, Menu*>();
|
|
||||||
return *map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu* Menu::from_menu_id(int menu_id)
|
Menu* Menu::from_menu_id(int menu_id)
|
||||||
|
|
|
@ -15,13 +15,10 @@
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
static FontDatabase* s_the;
|
|
||||||
|
|
||||||
FontDatabase& FontDatabase::the()
|
FontDatabase& FontDatabase::the()
|
||||||
{
|
{
|
||||||
if (!s_the)
|
static FontDatabase s_the;
|
||||||
s_the = new FontDatabase;
|
return s_the;
|
||||||
return *s_the;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static RefPtr<Font> s_default_font;
|
static RefPtr<Font> s_default_font;
|
||||||
|
|
|
@ -11,8 +11,8 @@ namespace Web {
|
||||||
|
|
||||||
ContentFilter& ContentFilter::the()
|
ContentFilter& ContentFilter::the()
|
||||||
{
|
{
|
||||||
static ContentFilter* filter = new ContentFilter;
|
static ContentFilter filter;
|
||||||
return *filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentFilter::ContentFilter()
|
ContentFilter::ContentFilter()
|
||||||
|
|
|
@ -10,10 +10,8 @@ namespace Clipboard {
|
||||||
|
|
||||||
Storage& Storage::the()
|
Storage& Storage::the()
|
||||||
{
|
{
|
||||||
static Storage* s_the;
|
static Storage s_the;
|
||||||
if (!s_the)
|
return s_the;
|
||||||
s_the = new Storage;
|
|
||||||
return *s_the;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::Storage()
|
Storage::Storage()
|
||||||
|
|
|
@ -8,10 +8,8 @@
|
||||||
|
|
||||||
WindowList& WindowList::the()
|
WindowList& WindowList::the()
|
||||||
{
|
{
|
||||||
static WindowList* s_the;
|
static WindowList s_the;
|
||||||
if (!s_the)
|
return s_the;
|
||||||
s_the = new WindowList;
|
|
||||||
return *s_the;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Window* WindowList::find_parent(const Window& window)
|
Window* WindowList::find_parent(const Window& window)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue