-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improved score openning speed by optimisation the searchTemplateForInstrNameList function #25971
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -853,19 +853,28 @@ const InstrumentTemplate* searchTemplateForInstrNameList(const std::list<String> | |
{ | ||
const InstrumentTemplate* bestMatch = nullptr; // default if no matches | ||
int bestMatchStrength = 0; // higher for better matches | ||
for (const InstrumentGroup* g : instrumentGroups) { | ||
for (const InstrumentTemplate* it : g->instrumentTemplates) { | ||
for (const String& name : nameList) { | ||
if (name.isEmpty() || it->useDrumset != useDrumset) { | ||
|
||
for (String name : nameList) { | ||
if (name.isEmpty()) { | ||
continue; | ||
} | ||
|
||
if (!caseSensitive) { | ||
name = name.toLower(); | ||
} | ||
StaffName instrName(name); | ||
|
||
for (const InstrumentGroup* g : instrumentGroups) { | ||
for (const InstrumentTemplate* it : g->instrumentTemplates) { | ||
if (it->useDrumset != useDrumset) { | ||
continue; | ||
} | ||
|
||
String trackName = it->trackName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoiding another string copy: const String& trackName = caseSensitive ? it->trackName : it->trackName.toLower(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I cant change it if you insist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I'm happy with it. Thanks for the explanation! |
||
StaffNameList longNames = it->longNames; | ||
StaffNameList shortNames = it->shortNames; | ||
String instrName = name; | ||
|
||
if (!caseSensitive) { | ||
instrName = instrName.toLower(); | ||
trackName = trackName.toLower(); | ||
for (StaffName& n : longNames) { | ||
n.setName(n.name().toLower()); | ||
|
@@ -876,9 +885,9 @@ const InstrumentTemplate* searchTemplateForInstrNameList(const std::list<String> | |
} | ||
|
||
int matchStrength = 0 | ||
+ (4 * (trackName == instrName ? 1 : 0)) // most weight to track name since there are fewer duplicates | ||
+ (2 * (muse::contains(longNames, StaffName(instrName)) ? 1 : 0)) | ||
+ (1 * (muse::contains(shortNames, StaffName(instrName)) ? 1 : 0)); // least weight to short name | ||
+ (4 * (trackName == name ? 1 : 0)) // most weight to track name since there are fewer duplicates | ||
+ (2 * (muse::contains(longNames, instrName) ? 1 : 0)) | ||
+ (1 * (muse::contains(shortNames, instrName) ? 1 : 0)); // least weight to short name | ||
const int perfectMatchStrength = 7; | ||
assert(matchStrength <= perfectMatchStrength); | ||
if (matchStrength > bestMatchStrength) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might help too by avoiding copying strings unnecessarily: