diff --git a/src/ID.cc b/src/ID.cc index f666c86cf0..0e2f7575a0 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -576,14 +576,16 @@ void ID::UpdateValID() { } #endif -void ID::AddOptionHandler(FuncPtr callback, int priority) { option_handlers.emplace(priority, std::move(callback)); } +void ID::AddOptionHandler(FuncPtr callback, int priority) { + option_handlers.emplace_front(priority, callback); + option_handlers.sort( + [](const OptionHandler& left, const OptionHandler& right) { return left.first < right.first; }); +} std::vector ID::GetOptionHandlers() const { - // multimap is sorted - // It might be worth caching this if we expect it to be called - // a lot... + // It might be worth caching this if we expect it to be called a lot... std::vector v; - for ( auto& element : option_handlers ) + for ( const auto& element : option_handlers ) v.push_back(element.second.get()); return v; } diff --git a/src/ID.h b/src/ID.h index 41498df005..b282d11904 100644 --- a/src/ID.h +++ b/src/ID.h @@ -2,7 +2,7 @@ #pragma once -#include +#include #include #include #include @@ -172,7 +172,8 @@ protected: AttributesPtr attrs; // contains list of functions that are called when an option changes - std::multimap option_handlers; + using OptionHandler = std::pair; + std::forward_list option_handlers; // Information managed by script optimization. We package this // up into a separate object for purposes of modularity, and,