diff --git a/src/Func.cc b/src/Func.cc index f3f41ae7d0..e6047df71e 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -295,10 +295,8 @@ ScriptFunc::ScriptFunc(std::string _name, FuncTypePtr ft, std::vector b std::ranges::stable_sort(bodies, std::ranges::greater(), &Body::priority); - if ( ! bodies.empty() ) { - current_body = bodies[0].stmts; - current_priority = bodies[0].priority; - } + if ( ! bodies.empty() ) + current_body = bodies[0]; } ScriptFunc::~ScriptFunc() { @@ -562,13 +560,9 @@ void ScriptFunc::AddBody(StmtPtr new_body, const std::vector& new_inits, bodies.clear(); } - Body b; - b.stmts = new_body; - b.groups = {groups.begin(), groups.end()}; - current_body = new_body; - current_priority = b.priority = priority; + current_body = Body{.stmts = new_body, .groups = {groups.begin(), groups.end()}, .priority = priority}; - bodies.push_back(std::move(b)); + bodies.push_back(current_body); std::ranges::stable_sort(bodies, std::ranges::greater(), &Body::priority); } @@ -577,18 +571,15 @@ void ScriptFunc::ReplaceBody(const StmtPtr& old_body, StmtPtr new_body) { for ( auto body = bodies.begin(); body != bodies.end(); ++body ) if ( body->stmts.get() == old_body.get() ) { - if ( new_body ) { + if ( new_body ) body->stmts = new_body; - current_priority = body->priority; - } else bodies.erase(body); found_it = true; + current_body = *body; break; } - - current_body = new_body; } bool ScriptFunc::DeserializeCaptures(BrokerListView data) { diff --git a/src/Func.h b/src/Func.h index 250e77c44f..8ec5405bbf 100644 --- a/src/Func.h +++ b/src/Func.h @@ -265,8 +265,9 @@ public: */ void ReplaceBody(const detail::StmtPtr& old_body, detail::StmtPtr new_body); - StmtPtr CurrentBody() const { return current_body; } - int CurrentPriority() const { return current_priority; } + StmtPtr CurrentBody() const { return current_body.stmts; } + int CurrentPriority() const { return current_body.priority; } + auto CurrentEventGroups() const { return current_body.groups; } /** * Returns the function's frame size. @@ -322,11 +323,8 @@ private: OffsetMap* captures_offset_mapping = nullptr; - // The most recently added/updated body ... - StmtPtr current_body; - - // ... and its priority. - int current_priority = 0; + // A copy of the most recently added/updated Body. + Body current_body; }; using built_in_func = ValPtr (*)(Frame* frame, const Args* args);