Func: Use std::stable_sort() for sorting bodies by priority

Avoids platform/stdlib dependent sorting of bodies with the same
priority and the same handler. They should be guaranteed to be
executed in load order now.
This commit is contained in:
Arne Welzel 2022-12-09 15:17:43 +01:00
parent 63aaf91bf7
commit 7ca78ea195

View file

@ -303,7 +303,7 @@ ScriptFunc::ScriptFunc(std::string _name, FuncTypePtr ft, std::vector<StmtPtr> b
bodies.push_back(b);
}
sort(bodies.begin(), bodies.end());
std::stable_sort(bodies.begin(), bodies.end());
if ( ! bodies.empty() )
{
@ -566,7 +566,7 @@ void ScriptFunc::AddBody(StmtPtr new_body, const std::vector<IDPtr>& new_inits,
current_priority = b.priority = priority;
bodies.push_back(b);
sort(bodies.begin(), bodies.end());
std::stable_sort(bodies.begin(), bodies.end());
}
void ScriptFunc::ReplaceBody(const StmtPtr& old_body, StmtPtr new_body)