diff --git a/src/script_opt/Inline.cc b/src/script_opt/Inline.cc index a73d9220d2..76e63ce6d3 100644 --- a/src/script_opt/Inline.cc +++ b/src/script_opt/Inline.cc @@ -24,13 +24,13 @@ void Inliner::Analyze() std::unordered_set cs; // Aspirational .... - non_recursive_funcs.insert(f->Func()); + non_recursive_funcs.insert(f.Func()); - for ( auto& func : f->Profile()->ScriptCalls() ) + for ( auto& func : f.Profile()->ScriptCalls() ) { cs.insert(func); - if ( func == f->Func() ) + if ( func == f.Func() ) { if ( report_recursive ) printf("%s is directly recursive\n", @@ -40,7 +40,7 @@ void Inliner::Analyze() } } - call_set[f->Func()] = cs; + call_set[f.Func()] = cs; } // Transitive closure. If we had any self-respect, we'd implement @@ -118,11 +118,11 @@ void Inliner::Analyze() // sizes for them correctly, and more fundamentally since // we don't compile them and hence inlining them will // make the parent non-compilable. - if ( f->Func()->Flavor() == FUNC_FLAVOR_FUNCTION && - non_recursive_funcs.count(f->Func()) > 0 && - f->Profile()->NumLambdas() == 0 && - f->Profile()->NumWhenStmts() == 0 ) - inline_ables.insert(f->Func()); + if ( f.Func()->Flavor() == FUNC_FLAVOR_FUNCTION && + non_recursive_funcs.count(f.Func()) > 0 && + f.Profile()->NumLambdas() == 0 && + f.Profile()->NumWhenStmts() == 0 ) + inline_ables.insert(f.Func()); for ( auto& f : funcs ) { @@ -134,8 +134,8 @@ void Inliner::Analyze() // circumstances in which a Zeek function can be called // not ultimately stemming from an event (such as global // scripting, or expiration functions). - if ( inline_ables.count(f->Func()) == 0 ) - InlineFunction(f); + if ( inline_ables.count(f.Func()) == 0 ) + InlineFunction(&f); } } diff --git a/src/script_opt/Inline.h b/src/script_opt/Inline.h index 7db9b80516..cb27dc3c0f 100644 --- a/src/script_opt/Inline.h +++ b/src/script_opt/Inline.h @@ -19,7 +19,7 @@ public: // First argument is a collection of information about *all* of // the script functions. Second argument states whether to report // recursive functions (of interest as they're not in-lineable). - Inliner(std::vector& _funcs, bool _report_recursive) + Inliner(std::vector& _funcs, bool _report_recursive) : funcs(_funcs), report_recursive(_report_recursive) { Analyze(); } @@ -40,7 +40,7 @@ protected: // Information about all of the functions (and events/hooks) in // the full set of scripts. - std::vector& funcs; + std::vector& funcs; // Functions that we've determined to be suitable for inlining. std::unordered_set inline_ables; diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index f61a1592e0..14ee06eb59 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -12,19 +12,19 @@ namespace zeek::detail { std::unordered_set non_recursive_funcs; // Tracks all of the loaded functions (including event handlers and hooks). -static std::vector funcs; +static std::vector funcs; -FuncInfo::~FuncInfo() - { - delete pf; - delete save_file; - } +FuncInfo::FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body) + : func(std::move(_func)), scope(std::move(_scope)), body(std::move(_body)) + {} + +void FuncInfo::SetProfile(std::unique_ptr _pf) + { pf = std::move(_pf); } void analyze_func(ScriptFuncPtr f) { - auto info = new FuncInfo(f, {NewRef{}, f->GetScope()}, f->CurrentBody()); - funcs.push_back(info); + funcs.emplace_back(f, ScopePtr{NewRef{}, f->GetScope()}, f->CurrentBody()); } static void check_env_opt(const char* opt, bool& opt_flag) @@ -50,8 +50,8 @@ void analyze_scripts(Options& opts) for ( auto& f : funcs ) { - f->SetProfile(new ProfileFunc(true)); - f->Body()->Traverse(f->Profile()); + f.SetProfile(std::make_unique(true)); + f.Body()->Traverse(f.Profile()); } Inliner* inl = nullptr; diff --git a/src/script_opt/ScriptOpt.h b/src/script_opt/ScriptOpt.h index 5d41feb8d0..81e6905a9d 100644 --- a/src/script_opt/ScriptOpt.h +++ b/src/script_opt/ScriptOpt.h @@ -32,34 +32,27 @@ using ScriptFuncPtr = IntrusivePtr; // Info we need for tracking an instance of a function. class FuncInfo { public: - FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body) - { - func = std::move(_func); - scope = std::move(_scope); - body = std::move(_body); - } - - ~FuncInfo(); + FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body); ScriptFunc* Func() { return func.get(); } ScriptFuncPtr FuncPtr() { return func; } ScopePtr Scope() { return scope; } StmtPtr Body() { return body; } - ProfileFunc* Profile() { return pf; } - const char* SaveFile() { return save_file; } + ProfileFunc* Profile() { return pf.get(); } + const std::string& SaveFile() { return save_file; } - void SetProfile(ProfileFunc* _pf) { pf = _pf; } - void SetSaveFile(const char* _sf); + void SetProfile(std::unique_ptr _pf); + void SetSaveFile(std::string _sf) { save_file = std::move(_sf); } protected: ScriptFuncPtr func; ScopePtr scope; StmtPtr body; - ProfileFunc* pf = nullptr; + std::unique_ptr pf; // If we're saving this function in a file, this is the name // of the file to use. - char* save_file = nullptr; + std::string save_file; };