File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 55 "slices"
66 "strings"
77 "unicode"
8+ "unsafe"
89
910 "github.com/microsoft/typescript-go/internal/stringutil"
1011)
@@ -613,7 +614,17 @@ func ToFileNameLowerCase(fileName string) string {
613614 }
614615 b [i ] = c
615616 }
616- return string (b )
617+ // SAFETY: We construct a string that aliases b’s backing array without copying.
618+ // (1) Lifetime: The address of b’s elements escapes via the returned string,
619+ // so escape analysis allocates b’s backing array on the heap. The string
620+ // header points to that heap allocation, ensuring it remains live for the
621+ // string’s lifetime.
622+ // (2) Initialization: We assign to every b[i] before creating the string.
623+ // (Note: Go zeroes all allocated memory, so “uninitialized” bytes cannot occur.)
624+ // (3) Immutability: We do not modify b after this point, so the string view
625+ // observes immutable data.
626+ // (4) Non-empty: On this path len(b) > 0, so &b[0] is a valid, non-nil pointer.
627+ return unsafe .String (& b [0 ], len (b ))
617628 }
618629
619630 return strings .Map (func (r rune ) rune {
You can’t perform that action at this time.
0 commit comments