mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Use sorted forward_list instead of multimap for ID option change handlers
This commit is contained in:
parent
020dd1a848
commit
035b4a4a8e
2 changed files with 10 additions and 7 deletions
12
src/ID.cc
12
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<Func*> 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<Func*> v;
|
||||
for ( auto& element : option_handlers )
|
||||
for ( const auto& element : option_handlers )
|
||||
v.push_back(element.second.get());
|
||||
return v;
|
||||
}
|
||||
|
|
5
src/ID.h
5
src/ID.h
|
@ -2,7 +2,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <forward_list>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_set>
|
||||
|
@ -172,7 +172,8 @@ protected:
|
|||
AttributesPtr attrs;
|
||||
|
||||
// contains list of functions that are called when an option changes
|
||||
std::multimap<int, FuncPtr> option_handlers;
|
||||
using OptionHandler = std::pair<int, FuncPtr>;
|
||||
std::forward_list<OptionHandler> option_handlers;
|
||||
|
||||
// Information managed by script optimization. We package this
|
||||
// up into a separate object for purposes of modularity, and,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue