Avoid calling `GetDeferredInitializers()` repeatedly

This commit is contained in:
Yonas Habteab 2022-08-26 17:21:12 +02:00
parent bb99106926
commit 38313434d2
1 changed files with 10 additions and 7 deletions

View File

@ -15,21 +15,24 @@ boost::thread_specific_ptr<Loader::DeferredInitializerPriorityQueue>& Loader::Ge
void Loader::ExecuteDeferredInitializers() void Loader::ExecuteDeferredInitializers()
{ {
if (!GetDeferredInitializers().get()) auto& initializers = GetDeferredInitializers();
if (!initializers.get())
return; return;
while (!GetDeferredInitializers().get()->empty()) { while (!initializers->empty()) {
DeferredInitializer initializer = GetDeferredInitializers().get()->top(); DeferredInitializer initializer = initializers->top();
GetDeferredInitializers().get()->pop(); initializers->pop();
initializer(); initializer();
} }
} }
void Loader::AddDeferredInitializer(const std::function<void()>& callback, InitializePriority priority) void Loader::AddDeferredInitializer(const std::function<void()>& callback, InitializePriority priority)
{ {
if (!GetDeferredInitializers().get()) auto& initializers = GetDeferredInitializers();
GetDeferredInitializers().reset(new Loader::DeferredInitializerPriorityQueue()); if (!initializers.get()) {
initializers.reset(new Loader::DeferredInitializerPriorityQueue());
}
GetDeferredInitializers().get()->push(DeferredInitializer(callback, priority)); initializers->push(DeferredInitializer(callback, priority));
} }