From 85f8839af150f95e39dd962f20de8ca48b155215 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 9 Nov 2022 11:34:37 +0100 Subject: [PATCH] Expression#Evaluate(): avoid Defer, and malloc(), via try-catch Defer is good for K. I. S. S., but with many objects and apply rules Expression#Evaluate() is called very often. --- lib/config/expression.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index 09b860cde..a83177bc9 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -38,6 +38,8 @@ void Expression::ScriptBreakpoint(ScriptFrame& frame, ScriptError *ex, const Deb ExpressionResult Expression::Evaluate(ScriptFrame& frame, DebugHint *dhint) const { + ExpressionResult result (Empty); + try { #ifdef I2_DEBUG /* std::ostringstream msgbuf; @@ -48,11 +50,15 @@ ExpressionResult Expression::Evaluate(ScriptFrame& frame, DebugHint *dhint) cons frame.IncreaseStackDepth(); - Defer decreaseStackDepth([&frame]{ + try { + result = DoEvaluate(frame, dhint); + } catch (...) { frame.DecreaseStackDepth(); - }); + throw; + } + + frame.DecreaseStackDepth(); - ExpressionResult result = DoEvaluate(frame, dhint); return result; } catch (ScriptError& ex) { ScriptBreakpoint(frame, &ex, GetDebugInfo());