Skip to content

Commit ed36b13

Browse files
committed
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<RuleMessage>. - Leverage std::make_shared & auto to simplify code.
1 parent 6eca48e commit ed36b13

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/rule_with_actions.cc

+7-10
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ RuleWithActions::~RuleWithActions() {
172172

173173

174174
bool RuleWithActions::evaluate(Transaction *transaction) {
175-
RuleMessage rm(this, transaction);
176-
std::shared_ptr<RuleMessage> rm2 = std::make_shared<RuleMessage>(&rm);
177-
return evaluate(transaction, rm2);
175+
return evaluate(transaction, std::make_shared<RuleMessage>(this, transaction));
178176
}
179177

180178

@@ -330,7 +328,7 @@ inline void RuleWithActions::executeTransformation(
330328
std::string newValue = a->evaluate(*oldValue, trans);
331329

332330
if (newValue != *oldValue) {
333-
std::shared_ptr<std::string> u(new std::string(newValue));
331+
auto u = std::make_shared<std::string>(newValue);
334332
if (m_containsMultiMatchAction) {
335333
ret->push_back(std::make_pair(u, a->m_name));
336334
(*nth)++;
@@ -355,14 +353,13 @@ void RuleWithActions::executeTransformations(
355353
int none = 0;
356354
int transformations = 0;
357355
std::string path("");
358-
std::shared_ptr<std::string> value =
359-
std::shared_ptr<std::string>(new std::string(in));
356+
auto value = std::make_shared<std::string>(in);
360357

361358
if (m_containsMultiMatchAction == true) {
362359
/* keep the original value */
363360
ret.push_back(std::make_pair(
364-
std::shared_ptr<std::string>(new std::string(*value)),
365-
std::shared_ptr<std::string>(new std::string(path))));
361+
std::make_shared<std::string>(*value),
362+
std::make_shared<std::string>(path)));
366363
}
367364

368365
for (Action *a : m_transformations) {
@@ -436,8 +433,8 @@ void RuleWithActions::executeTransformations(
436433

437434
if (!m_containsMultiMatchAction) {
438435
ret.push_back(std::make_pair(
439-
std::shared_ptr<std::string>(new std::string(*value)),
440-
std::shared_ptr<std::string>(new std::string(path))));
436+
std::make_shared<std::string>(*value),
437+
std::make_shared<std::string>(path)));
441438
}
442439
}
443440

0 commit comments

Comments
 (0)