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()
{
if (!GetDeferredInitializers().get())
auto& initializers = GetDeferredInitializers();
if (!initializers.get())
return;
while (!GetDeferredInitializers().get()->empty()) {
DeferredInitializer initializer = GetDeferredInitializers().get()->top();
GetDeferredInitializers().get()->pop();
while (!initializers->empty()) {
DeferredInitializer initializer = initializers->top();
initializers->pop();
initializer();
}
}
void Loader::AddDeferredInitializer(const std::function<void()>& callback, InitializePriority priority)
{
if (!GetDeferredInitializers().get())
GetDeferredInitializers().reset(new Loader::DeferredInitializerPriorityQueue());
auto& initializers = GetDeferredInitializers();
if (!initializers.get()) {
initializers.reset(new Loader::DeferredInitializerPriorityQueue());
}
GetDeferredInitializers().get()->push(DeferredInitializer(callback, priority));
initializers->push(DeferredInitializer(callback, priority));
}