Skip to content

Commit

Permalink
Merge pull request #4767 from uklotzde/qjsvaluelist
Browse files Browse the repository at this point in the history
QJSValueList: Minor optimization
  • Loading branch information
Swiftb0y authored May 24, 2022
2 parents 6c5bf2a + a4b7c20 commit 7672cf1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
13 changes: 7 additions & 6 deletions src/controllers/midi/midicontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,13 @@ void MidiController::processInputMapping(const MidiInputMapping& mapping,
}

QJSValue function = pEngine->wrapFunctionCode(mapping.control.item, 5);
QJSValueList args;
args << QJSValue(channel);
args << QJSValue(control);
args << QJSValue(value);
args << QJSValue(status);
args << QJSValue(mapping.control.group);
const auto args = QJSValueList{
channel,
control,
value,
status,
mapping.control.group,
};
if (!pEngine->executeFunction(function, args)) {
qCWarning(m_logBase) << "MidiController: Invalid script function"
<< mapping.control.item;
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/scripting/controllerscriptenginebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ControllerScriptEngineBase : public QObject {

virtual bool initialize();

bool executeFunction(QJSValue functionObject, const QJSValueList& arguments);
bool executeFunction(QJSValue functionObject, const QJSValueList& arguments = {});

/// Shows a UI dialog notifying of a script evaluation error.
/// Precondition: QJSValue.isError() == true
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/scripting/controllerscriptmoduleengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool ControllerScriptModuleEngine::initialize() {
}

QJSValue initFunction = mod.property("init");
if (!executeFunction(initFunction, QJSValueList{})) {
if (!executeFunction(initFunction)) {
shutdown();
return false;
}
Expand All @@ -47,6 +47,6 @@ bool ControllerScriptModuleEngine::initialize() {
}

void ControllerScriptModuleEngine::shutdown() {
executeFunction(m_shutdownFunction, QJSValueList());
executeFunction(m_shutdownFunction);
ControllerScriptEngineBase::shutdown();
}
20 changes: 10 additions & 10 deletions src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,12 @@ bool ControllerScriptEngineLegacy::initialize() {
wrapFunctionCode(functionName, 2)));
}

QJSValueList args;
if (m_pController) {
args << QJSValue(m_pController->getName());
} else { // m_pController is nullptr in tests.
args << QJSValue();
}
args << QJSValue(m_logger().isDebugEnabled());
// m_pController is nullptr in tests.
const auto controllerName = m_pController ? m_pController->getName() : QString{};
const auto args = QJSValueList{
controllerName,
m_logger().isDebugEnabled(),
};
if (!callFunctionOnObjects(m_scriptFunctionPrefixes, "init", args, true)) {
shutdown();
return false;
Expand All @@ -182,9 +181,10 @@ bool ControllerScriptEngineLegacy::handleIncomingData(const QByteArray& data) {
return false;
}

QJSValueList args;
args << m_pJSEngine->toScriptValue(data);
args << QJSValue(static_cast<uint>(data.size()));
const auto args = QJSValueList{
m_pJSEngine->toScriptValue(data),
static_cast<uint>(data.size()),
};

for (const QJSValue& function : std::as_const(m_incomingDataFunctions)) {
ControllerScriptEngineBase::executeFunction(function, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ControllerScriptEngineLegacy : public ControllerScriptEngineBase {
QJSValue wrapArrayBufferCallback(const QJSValue& callback);
bool callFunctionOnObjects(const QList<QString>& scriptFunctionPrefixes,
const QString&,
const QJSValueList& args = QJSValueList(),
const QJSValueList& args = {},
bool bFatalError = false);

QJSValue m_makeArrayBufferWrapperFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void ControllerScriptInterfaceLegacy::timerEvent(QTimerEvent* event) {
stopTimer(timerId);
}

m_pScriptEngineLegacy->executeFunction(timerTarget.callback, QJSValueList());
m_pScriptEngineLegacy->executeFunction(timerTarget.callback);
}

void ControllerScriptInterfaceLegacy::softTakeover(
Expand Down
9 changes: 5 additions & 4 deletions src/controllers/scripting/legacy/scriptconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#include "controllers/scripting/legacy/controllerscriptenginelegacy.h"

void ScriptConnection::executeCallback(double value) const {
QJSValueList args;
args << QJSValue(value);
args << QJSValue(key.group);
args << QJSValue(key.item);
const auto args = QJSValueList{
value,
key.group,
key.item,
};
QJSValue func = callback; // copy function because QJSValue::call is not const
QJSValue result = func.call(args);
if (result.isError()) {
Expand Down

0 comments on commit 7672cf1

Please sign in to comment.