From fef419f9869bd5b160683011f284fde585e6667f Mon Sep 17 00:00:00 2001 From: Eduardo Arias Date: Tue, 23 Apr 2024 16:22:58 -0300 Subject: [PATCH] Minor changes related to std::shared_ptr usage in RuleWithActions - RuleWithActions::evaluate(Transaction *transaction) - Removed temporary rm local variable used to immediately create std::shared_ptr. - Leverage std::make_shared & auto to simplify code. --- src/rule_with_actions.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/rule_with_actions.cc b/src/rule_with_actions.cc index df323c4b..5ae7d407 100644 --- a/src/rule_with_actions.cc +++ b/src/rule_with_actions.cc @@ -172,9 +172,7 @@ RuleWithActions::~RuleWithActions() { bool RuleWithActions::evaluate(Transaction *transaction) { - RuleMessage rm(this, transaction); - std::shared_ptr rm2 = std::make_shared(&rm); - return evaluate(transaction, rm2); + return evaluate(transaction, std::make_shared(this, transaction)); } @@ -330,7 +328,7 @@ inline void RuleWithActions::executeTransformation( std::string newValue = a->evaluate(*oldValue, trans); if (newValue != *oldValue) { - std::shared_ptr u(new std::string(newValue)); + auto u = std::make_shared(newValue); if (m_containsMultiMatchAction) { ret->push_back(std::make_pair(u, a->m_name)); (*nth)++; @@ -355,14 +353,13 @@ void RuleWithActions::executeTransformations( int none = 0; int transformations = 0; std::string path(""); - std::shared_ptr value = - std::shared_ptr(new std::string(in)); + auto value = std::make_shared(in); if (m_containsMultiMatchAction == true) { /* keep the original value */ ret.push_back(std::make_pair( - std::shared_ptr(new std::string(*value)), - std::shared_ptr(new std::string(path)))); + std::make_shared(*value), + std::make_shared(path))); } for (Action *a : m_transformations) { @@ -436,8 +433,8 @@ void RuleWithActions::executeTransformations( if (!m_containsMultiMatchAction) { ret.push_back(std::make_pair( - std::shared_ptr(new std::string(*value)), - std::shared_ptr(new std::string(path)))); + std::make_shared(*value), + std::make_shared(path))); } }