diff --git a/src/script_opt/Reduce.cc b/src/script_opt/Reduce.cc index 05b5efc283..1fdde4e4d4 100644 --- a/src/script_opt/Reduce.cc +++ b/src/script_opt/Reduce.cc @@ -15,17 +15,6 @@ namespace zeek::detail { -Reducer::Reducer(Scope* s) - { - scope = s; - } - -Reducer::~Reducer() - { - for ( int i = 0; i < temps.length(); ++i ) - delete temps[i]; - } - ExprPtr Reducer::GenTemporaryExpr(const TypePtr& t, ExprPtr rhs) { auto e = make_intrusive(GenTemporary(t, rhs)); @@ -38,7 +27,7 @@ NameExprPtr Reducer::UpdateName(NameExprPtr n) if ( NameIsReduced(n.get()) ) return n; - return make_intrusive(FindNewLocal(n.get())); + return make_intrusive(FindNewLocal(n)); } bool Reducer::NameIsReduced(const NameExpr* n) const @@ -80,7 +69,7 @@ bool Reducer::IDsAreReduced(const IDPList* ids) const bool Reducer::IDsAreReduced(const std::vector& ids) const { - for ( auto& id : ids ) + for ( const auto& id : ids ) if ( ! ID_IsReduced(id) ) return false; @@ -92,7 +81,7 @@ IDPtr Reducer::UpdateID(IDPtr id) if ( ID_IsReduced(id) ) return id; - return FindNewLocal(id.get()); + return FindNewLocal(id); } bool Reducer::ID_IsReduced(const ID* id) const @@ -103,7 +92,7 @@ bool Reducer::ID_IsReduced(const ID* id) const NameExprPtr Reducer::GenInlineBlockName(IDPtr id) { - return make_intrusive(GenLocal(id.get())); + return make_intrusive(GenLocal(id)); } NameExprPtr Reducer::PushInlineBlock(TypePtr type) @@ -155,9 +144,9 @@ IDPtr Reducer::GenTemporary(const TypePtr& t, ExprPtr rhs) return temp_id; } -IDPtr Reducer::FindNewLocal(ID* id) +IDPtr Reducer::FindNewLocal(const IDPtr& id) { - auto mapping = orig_to_new_locals.find(id); + auto mapping = orig_to_new_locals.find(id.get()); if ( mapping != orig_to_new_locals.end() ) return mapping->second; @@ -165,7 +154,7 @@ IDPtr Reducer::FindNewLocal(ID* id) return GenLocal(id); } -IDPtr Reducer::GenLocal(ID* orig) +IDPtr Reducer::GenLocal(const IDPtr& orig) { if ( Optimizing() ) reporter->InternalError("Generating a new local while optimizing"); @@ -179,7 +168,7 @@ IDPtr Reducer::GenLocal(ID* orig) local_id->SetAttrs(orig->GetAttrs()); new_locals.insert(local_id.get()); - orig_to_new_locals[orig] = local_id; + orig_to_new_locals[orig.get()] = local_id; return local_id; } diff --git a/src/script_opt/Reduce.h b/src/script_opt/Reduce.h index 9a2a1d3088..c172681740 100644 --- a/src/script_opt/Reduce.h +++ b/src/script_opt/Reduce.h @@ -15,8 +15,7 @@ class ProfileFunc; class Reducer { public: - Reducer(Scope* s); - ~Reducer(); + Reducer() { } StmtPtr Reduce(StmtPtr s) { @@ -160,15 +159,15 @@ protected: // Retrieve the identifier corresponding to the new local for // the given expression. Creates the local if necessary. - IDPtr FindNewLocal(ID* id); - IDPtr FindNewLocal(const NameExpr* n) - { return FindNewLocal(n->Id()); } + IDPtr FindNewLocal(const IDPtr& id); + IDPtr FindNewLocal(const NameExprPtr& n) + { return FindNewLocal(n->IdPtr()); } // Generate a new local to use in lieu of the original (seen // in an inlined block). The difference is that the new // version has a distinct name and has a correct frame offset // for the current function. - IDPtr GenLocal(ID* orig); + IDPtr GenLocal(const IDPtr& orig); // Track that we're replacing instances of "orig" with a new // expression. This allows us to locate the RDs associated diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index e635ff79e6..70cdd10b1f 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -49,7 +49,7 @@ void optimize_func(ScriptFunc* f, std::shared_ptr pf, auto scope = scope_ptr.release(); push_existing_scope(scope); - auto rc = std::make_shared(scope); + auto rc = std::make_shared(); auto new_body = rc->Reduce(body); if ( reporter->Errors() > 0 )