From 208692b18a1ddc53a569cde292e461a916a5c4d8 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:47:40 +0200 Subject: [PATCH] fixup! refactor: optimize PortMidi namematching by delaying QString creation --- src/controllers/midi/portmidienumerator.cpp | 46 ++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/controllers/midi/portmidienumerator.cpp b/src/controllers/midi/portmidienumerator.cpp index a231506a946d..5617d312318c 100644 --- a/src/controllers/midi/portmidienumerator.cpp +++ b/src/controllers/midi/portmidienumerator.cpp @@ -2,14 +2,14 @@ #include -#include +#include #include #include "controllers/midi/portmidicontroller.h" #include "moc_portmidienumerator.cpp" #include "util/cmdlineargs.h" -using namespace Qt::StringLiterals; +using namespace Qt::Literals::StringLiterals; namespace { @@ -41,9 +41,9 @@ const QRegularExpression kOutputRegex(u"^(.*) out( \\d+)?( .*)?$"_s, const QRegularExpression kDeviceNameRegex(u"^(.*) (\\d+)( [^0-9]+)?$"_s); bool namesMatchRegexes(const QRegularExpression& kInputRegex, - QLatin1StringView input_name, + QLatin1String input_name, const QRegularExpression& kOutputRegex, - QLatin1StringView output_name) { + QLatin1String output_name) { QRegularExpressionMatch inputMatch = kInputRegex.match(input_name); if (inputMatch.hasMatch()) { QString inputDeviceName = inputMatch.captured(1); @@ -61,23 +61,23 @@ bool namesMatchRegexes(const QRegularExpression& kInputRegex, return false; } -bool namesMatchMidiPattern(QLatin1StringView input_name, - QLatin1StringView output_name) { +bool namesMatchMidiPattern(QLatin1String input_name, + QLatin1String output_name) { return namesMatchRegexes(kMidiDeviceNameRegex, input_name, kMidiDeviceNameRegex, output_name); } -bool namesMatchInOutPattern(QLatin1StringView input_name, - QLatin1StringView output_name) { +bool namesMatchInOutPattern(QLatin1String input_name, + QLatin1String output_name) { return namesMatchRegexes(kInputRegex, input_name, kOutputRegex, output_name); } bool namesMatchPattern(QLatin1String input_name, - QLatin1StringView output_name) { + QLatin1String output_name) { return namesMatchRegexes(kDeviceNameRegex, input_name, kDeviceNameRegex, output_name); } -bool namesMatchAllowableEdgeCases(QLatin1StringView input_name, - QLatin1StringView output_name) { +bool namesMatchAllowableEdgeCases(QLatin1String input_name, + QLatin1String output_name) { // Mac OS 10.12 & Korg Kaoss DJ 1.6: // Korg Kaoss DJ has input 'KAOSS DJ CONTROL' and output 'KAOSS DJ SOUND'. // This means it doesn't pass the shouldLinkInputToOutput test. Without an @@ -94,20 +94,20 @@ bool namesMatchAllowableEdgeCases(QLatin1StringView input_name, return false; } -bool namesMatch(QLatin1StringView input_name, QLatin1StringView output_name) { +bool namesMatch(QLatin1String input_name, QLatin1String output_name) { return namesMatchMidiPattern(input_name, output_name) || namesMatchInOutPattern(input_name, output_name) || namesMatchPattern(input_name, output_name); } -QLatin1StringView trimStart(QLatin1StringView str, QLatin1StringView trim) { +QLatin1String trimStart(QLatin1String str, QLatin1String trim) { if (str.startsWith(trim, Qt::CaseInsensitive)) { return str.sliced(trim.length()); } return str; } -QString trimMiddle(QLatin1StringView str, QLatin1StringView trim) { +QString trimMiddle(QLatin1String str, QLatin1String trim) { int offset = str.indexOf(trim, 0, Qt::CaseInsensitive); if (offset != -1) { return QString::fromLatin1(str).replace(offset, trim.length(), " "); @@ -135,8 +135,8 @@ PortMidiEnumerator::~PortMidiEnumerator() { } } -bool shouldLinkInputToOutput(QLatin1StringView input_name, - QLatin1StringView output_name) { +bool shouldLinkInputToOutput(QLatin1String input_name, + QLatin1String output_name) { // Early exit. if (input_name == output_name || namesMatchAllowableEdgeCases(input_name, output_name)) { return true; @@ -145,8 +145,8 @@ bool shouldLinkInputToOutput(QLatin1StringView input_name, // Some device drivers prepend "To" and "From" to the names of their MIDI // ports. If the output and input device names don't match, let's try // trimming those words from the start, and seeing if they then match. - QLatin1StringView input_name_trimmed = trimStart(input_name, "from"_L1); - QLatin1StringView output_name_trimmed = trimStart(output_name, "to"_L1); + QLatin1String input_name_trimmed = trimStart(input_name, "from"_L1); + QLatin1String output_name_trimmed = trimStart(output_name, "to"_L1); if (input_name_trimmed == output_name_trimmed) { return true; @@ -158,8 +158,8 @@ bool shouldLinkInputToOutput(QLatin1StringView input_name, if (input_name_trimmed == output_name_trimmed || namesMatch(input_name, output_name) || namesMatch(input_name_trimmed, output_name_trimmed) || - namesMatch(QLatin1StringView(input_name_trimmed.latin1()), - QLatin1StringView(output_name_trimmed.latin1()))) { + namesMatch(QLatin1String(input_name_trimmed.latin1()), + QLatin1String(output_name_trimmed.latin1()))) { return true; } @@ -178,7 +178,7 @@ QList PortMidiEnumerator::queryDevices() { m_devices.clear(); - QMap unassignedOutputDevices; + QMap unassignedOutputDevices; // Build a complete list of output devices for later pairing for (int i = 0; i < numDevices; i++) { @@ -191,7 +191,7 @@ QList PortMidiEnumerator::queryDevices() { } qDebug() << " Found output device" << "#" << i << pDeviceInfo->name; - unassignedOutputDevices[i] = QLatin1StringView(pDeviceInfo->name); + unassignedOutputDevices[i] = QLatin1String(pDeviceInfo->name); } // Search for input devices and pair them with output devices if applicable @@ -217,7 +217,7 @@ QList PortMidiEnumerator::queryDevices() { int outputDevIndex = -1; //Search for a corresponding output device - QMapIterator j(unassignedOutputDevices); + QMapIterator j(unassignedOutputDevices); while (j.hasNext()) { j.next();