Skip to content

Commit

Permalink
Collect garbage and source scripts only once per client
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Mar 28, 2021
1 parent 2c4634c commit 1d61589
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/scriptable/scriptable.cpp
Expand Up @@ -2785,6 +2785,20 @@ int Scriptable::executeArguments(const QStringList &args)
if ( !sourceScriptCommands() )
return CommandError;

const int exitCode = executeArgumentsSimple(args);

if (exitCode == CommandFinished)
setActionData();

// Destroy objects so destructors are run before script finishes
// (e.g. file writes are flushed or temporary files are automatically removed).
m_engine->collectGarbage();

return exitCode;
}

int Scriptable::executeArgumentsSimple(const QStringList &args)
{
/* Special arguments:
* "-" read this argument from stdin
* "--" read all following arguments without control sequences
Expand Down Expand Up @@ -2856,13 +2870,6 @@ int Scriptable::executeArguments(const QStringList &args)
exitCode = CommandFinished;
}

if (exitCode == CommandFinished)
setActionData();

// Destroy objects so destructors are run before script finishes
// (e.g. file writes are flushed or temporary files are automatically removed).
m_engine->collectGarbage();

return exitCode;
}

Expand Down Expand Up @@ -3177,7 +3184,7 @@ bool Scriptable::runAction(Action *action)
const auto oldAction = m_action;
m_action = action;

const auto exitCode = executeArguments(cmd1.mid(1));
const auto exitCode = executeArgumentsSimple(cmd1.mid(1));
action->setExitCode(exitCode);
m_failed = false;
clearExceptions();
Expand Down
1 change: 1 addition & 0 deletions src/scriptable/scriptable.h
Expand Up @@ -160,6 +160,7 @@ class Scriptable final : public QObject
void setActionId(int actionId);
void setActionName(const QString &actionName);
int executeArguments(const QStringList &args);
int executeArgumentsSimple(const QStringList &args);

void abortEvaluation(Abort abort = Abort::AllEvaluations);

Expand Down

0 comments on commit 1d61589

Please sign in to comment.