Skip to content

Commit ae0b6e5

Browse files
authored
perf(tspath): optimize the fast path case for ToFileNameLowerCase (#1558)
1 parent cedc0cb commit ae0b6e5

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

internal/tspath/path.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,35 @@ func GetCanonicalFileName(fileName string, useCaseSensitiveFileNames bool) strin
534534
// they have corresponding upper case character so they dont need special handling
535535

536536
func ToFileNameLowerCase(fileName string) string {
537+
const IWithDot = '\u0130'
538+
539+
ascii := true
540+
needsLower := false
541+
for _, c := range []byte(fileName) {
542+
if c >= 0x80 {
543+
ascii = false
544+
break
545+
}
546+
if 'A' <= c && c <= 'Z' {
547+
needsLower = true
548+
}
549+
}
550+
if ascii {
551+
if !needsLower {
552+
return fileName
553+
}
554+
b := make([]byte, len(fileName))
555+
for i, c := range []byte(fileName) {
556+
if 'A' <= c && c <= 'Z' {
557+
c += 'a' - 'A' // +32
558+
}
559+
b[i] = c
560+
}
561+
return string(b)
562+
}
563+
537564
return strings.Map(func(r rune) rune {
538-
if r == '\u0130' {
565+
if r == IWithDot {
539566
return r
540567
}
541568
return unicode.ToLower(r)

0 commit comments

Comments
 (0)