Merge remote-tracking branch 'origin/topic/timw/lazy-allocate-id-option-handlers'

* origin/topic/timw/lazy-allocate-id-option-handlers:
  Move ID::type in structure to fill memory padding
  Use sorted forward_list instead of multimap for ID option change handlers
This commit is contained in:
Tim Wojtulewicz 2025-07-28 13:57:18 -07:00
commit 8aeaed69c5
4 changed files with 18 additions and 9 deletions

View file

@ -1,3 +1,9 @@
8.0.0-dev.763 | 2025-07-28 13:57:18 -0700
* Move ID::type in structure to fill memory padding (Tim Wojtulewicz, Corelight)
* Use sorted forward_list instead of multimap for ID option change handlers (Tim Wojtulewicz, Corelight)
8.0.0-dev.760 | 2025-07-28 13:12:47 -0700
* Remove intermediate cipher vectors in ssl-analyzer.pac (Tim Wojtulewicz, Corelight)

View file

@ -1 +1 @@
8.0.0-dev.760
8.0.0-dev.763

View file

@ -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;
}

View file

@ -2,7 +2,7 @@
#pragma once
#include <map>
#include <forward_list>
#include <string>
#include <string_view>
#include <unordered_set>
@ -157,9 +157,9 @@ protected:
#endif
const char* name;
TypePtr type;
IDScope scope;
bool is_export;
TypePtr type;
bool is_capture = false;
bool is_const = false;
bool is_enum_const = false;
@ -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,