Avoid unnecessary string copies for LiteralExpression objects

refs #12509
This commit is contained in:
Gunnar Beutner 2016-08-26 18:11:56 +02:00
parent c1a58446af
commit 7194b36d3e
2 changed files with 6 additions and 2 deletions

View File

@ -707,9 +707,8 @@ void icinga::BindToScope(Expression *& expr, ScopeSpecifier scopeSpec)
} }
LiteralExpression *lexpr = dynamic_cast<LiteralExpression *>(expr); LiteralExpression *lexpr = dynamic_cast<LiteralExpression *>(expr);
ScriptFrame frame;
if (lexpr && lexpr->Evaluate(frame).GetValue().IsString()) { if (lexpr && lexpr->GetValue().IsString()) {
Expression *scope = new GetScopeExpression(scopeSpec); Expression *scope = new GetScopeExpression(scopeSpec);
expr = new IndexerExpression(scope, lexpr, lexpr->GetDebugInfo()); expr = new IndexerExpression(scope, lexpr, lexpr->GetDebugInfo());
} }

View File

@ -239,6 +239,11 @@ class I2_CONFIG_API LiteralExpression : public Expression
public: public:
LiteralExpression(const Value& value = Value()); LiteralExpression(const Value& value = Value());
const Value& GetValue(void) const
{
return m_Value;
}
protected: protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override; virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;