Tweak FuncInfo memory management

Idea being for everything to be automatically released when process
exits just so there's less potential noise from leak profilers.
This commit is contained in:
Jon Siwek 2020-12-13 17:06:57 -08:00
parent c7bec09e14
commit 7b2ee2514e
4 changed files with 30 additions and 37 deletions

View file

@ -32,34 +32,27 @@ using ScriptFuncPtr = IntrusivePtr<ScriptFunc>;
// 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<ProfileFunc> _pf);
void SetSaveFile(std::string _sf) { save_file = std::move(_sf); }
protected:
ScriptFuncPtr func;
ScopePtr scope;
StmtPtr body;
ProfileFunc* pf = nullptr;
std::unique_ptr<ProfileFunc> 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;
};