Cache locals of script frame used for group assign where eval

to avoid malloc(). This BREAKS assign where locals.x = 1.
This commit is contained in:
Alexander A. Klimov 2022-11-15 12:51:13 +01:00
parent 805c78a7b9
commit 477d177b5a
2 changed files with 27 additions and 10 deletions

View File

@ -24,10 +24,20 @@ bool HostGroup::EvaluateObjectRule(const Host::Ptr& host, const ConfigItem::Ptr&
CONTEXT("Evaluating rule for group '" << groupName << "'");
ScriptFrame frame(true);
if (group->GetScope())
ScriptFrame frame (false);
if (group->GetScope()) {
frame.Locals = new Dictionary();
if (group->GetScope()) {
group->GetScope()->CopyTo(frame.Locals);
frame.Locals->Set("host", host);
}
host->GetFrozenLocalsForApply()->CopyTo(frame.Locals);
frame.Locals->Freeze();
} else {
frame.Locals = host->GetFrozenLocalsForApply();
}
if (!group->GetFilter()->Evaluate(frame).GetValue().ToBool())
return false;

View File

@ -24,13 +24,20 @@ bool ServiceGroup::EvaluateObjectRule(const Service::Ptr& service, const ConfigI
CONTEXT("Evaluating rule for group '" << groupName << "'");
Host::Ptr host = service->GetHost();
ScriptFrame frame (false);
ScriptFrame frame(true);
if (group->GetScope())
if (group->GetScope()) {
frame.Locals = new Dictionary();
if (group->GetScope()) {
group->GetScope()->CopyTo(frame.Locals);
frame.Locals->Set("host", host);
frame.Locals->Set("service", service);
}
service->GetFrozenLocalsForApply()->CopyTo(frame.Locals);
frame.Locals->Freeze();
} else {
frame.Locals = service->GetFrozenLocalsForApply();
}
if (!group->GetFilter()->Evaluate(frame).GetValue().ToBool())
return false;