Skip to content
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

perf: remove checking if a search string is an acronym #47235

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions src/libs/StringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,6 @@ function normalizeCRLF(value?: string): string | undefined {
return value?.replace(/\r\n/g, '\n');
}

/**
* Generates an acronym for a string.
* @param string the string for which to produce the acronym
* @returns the acronym
*/
function getAcronym(string: string): string {
let acronym = '';
const wordsInString = string.split(' ');
wordsInString.forEach((wordInString) => {
const splitByHyphenWords = wordInString.split('-');
splitByHyphenWords.forEach((splitByHyphenWord) => {
acronym += splitByHyphenWord.substring(0, 1);
});
});
return acronym;
}

/**
* Replace all line breaks with white spaces
*/
Expand All @@ -114,4 +97,4 @@ function getFirstLine(text = '') {
return lines[0];
}

export default {sanitizeString, isEmptyString, removeInvisibleCharacters, normalizeAccents, normalizeCRLF, getAcronym, lineBreaksToSpaces, getFirstLine};
export default {sanitizeString, isEmptyString, removeInvisibleCharacters, normalizeAccents, normalizeCRLF, lineBreaksToSpaces, getFirstLine};
17 changes: 5 additions & 12 deletions src/libs/filterArrayByMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
Use `threshold` option with one of the rankings defined below to control the strictness of the match.
*/
import type {ValueOf} from 'type-fest';
import StringUtils from './StringUtils';

const MATCH_RANK = {
CASE_SENSITIVE_EQUAL: 7,
EQUAL: 6,
STARTS_WITH: 5,
WORD_STARTS_WITH: 4,
CONTAINS: 3,
ACRONYM: 2,
CASE_SENSITIVE_EQUAL: 6,
EQUAL: 5,
STARTS_WITH: 4,
WORD_STARTS_WITH: 3,
CONTAINS: 2,
MATCHES: 1,
NO_MATCH: 0,
} as const;
Expand Down Expand Up @@ -62,11 +60,6 @@ function getMatchRanking(testString: string, stringToRank: string): Ranking {
return MATCH_RANK.NO_MATCH;
}

// acronym
if (StringUtils.getAcronym(lowercaseTestString).includes(lowercaseStringToRank)) {
return MATCH_RANK.ACRONYM;
}

// will return a number between rankings.MATCHES and rankings.MATCHES + 1 depending on how close of a match it is.
let matchingInOrderCharCount = 0;
let charNumber = 0;
Expand Down
20 changes: 0 additions & 20 deletions tests/unit/StringUtilsTest.ts

This file was deleted.

Loading