Skip to content

Commit

Permalink
reduce chances to bail-out onto toLowerCase in compareSubstringIgnore…
Browse files Browse the repository at this point in the history
…Case, #134075
  • Loading branch information
jrieken committed Oct 4, 2021
1 parent 80ca5cf commit 2f74087
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/vs/base/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,27 @@ export function compareSubstringIgnoreCase(a: string, b: string, aStart: number
continue;
}

const diff = codeA - codeB;
if (diff === 32 && isUpperAsciiLetter(codeB)) { //codeB =[65-90] && codeA =[97-122]
continue;

} else if (diff === -32 && isUpperAsciiLetter(codeA)) { //codeB =[97-122] && codeA =[65-90]
continue;
if (codeA >= 128 || codeB >= 128) {
// not ASCII letters -> fallback to lower-casing strings
return compareSubstring(a.toLowerCase(), b.toLowerCase(), aStart, aEnd, bStart, bEnd);
}

if (isLowerAsciiLetter(codeA) && isLowerAsciiLetter(codeB)) {
//
return diff;
// mapper lower-case ascii letter onto upper-case varinats
// [97-122] (lower ascii) --> [65-90] (upper ascii)
if (isLowerAsciiLetter(codeA)) {
codeA -= 32;
}
if (isLowerAsciiLetter(codeB)) {
codeB -= 32;
}

} else {
return compareSubstring(a.toLowerCase(), b.toLowerCase(), aStart, aEnd, bStart, bEnd);
// compare both code points
const diff = codeA - codeB;
if (diff === 0) {
continue;
}

return diff;
}

const aLen = aEnd - aStart;
Expand Down

0 comments on commit 2f74087

Please sign in to comment.