Skip to content

Commit

Permalink
perf: cache the length of the string that's iterated over
Browse files Browse the repository at this point in the history
  • Loading branch information
mart-jansink committed Dec 25, 2020
1 parent edd9853 commit 2b5a576
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function getClosenessRanking(testString: string, stringToRank: string): number {
string: string,
index: number,
) {
for (let j = index; j < string.length; j++) {
for (let j = index, J = string.length; j < J; j++) {
const stringChar = string[j]
if (stringChar === matchChar) {
matchingInOrderCharCount += 1
Expand All @@ -280,7 +280,7 @@ function getClosenessRanking(testString: string, stringToRank: string): number {
return rankings.NO_MATCH
}
charNumber = firstIndex
for (let i = 1; i < stringToRank.length; i++) {
for (let i = 1, I = stringToRank.length; i < I; i++) {
const matchChar = stringToRank[i]
charNumber = findMatchingCharacter(matchChar, testString, charNumber)
const found = charNumber > -1
Expand Down

0 comments on commit 2b5a576

Please sign in to comment.