From e5f305444025c0b677225485833f4923fa091a03 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Sat, 9 Aug 2025 21:34:27 -0400 Subject: [PATCH] Avoid copying content when writing files --- internal/vfs/iovfs/iofs.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/vfs/iovfs/iofs.go b/internal/vfs/iovfs/iofs.go index 8b4fd5777d..39e484937c 100644 --- a/internal/vfs/iovfs/iofs.go +++ b/internal/vfs/iovfs/iofs.go @@ -4,6 +4,7 @@ import ( "fmt" "io/fs" "strings" + "unsafe" "github.com/microsoft/typescript-go/internal/stringutil" "github.com/microsoft/typescript-go/internal/tspath" @@ -65,7 +66,8 @@ func From(fsys fs.FS, useCaseSensitiveFileNames bool) vfs.FS { // \xEF\xBB\xBF. content = stringutil.AddUTF8ByteOrderMark(content) } - return fsys.WriteFile(rest, []byte(content), 0o666) + buf := unsafe.Slice(unsafe.StringData(content), len(content)) + return fsys.WriteFile(rest, buf, 0o666) } mkdirAll = func(path string) error { rest, _ := strings.CutPrefix(path, "/")