txtar: use slices.Clone instead of copy
Use slices.Clone instead of copy now that x/tools uses Go >= 1.22.
Resolves an outstanding TODO.
Change-Id: Ia87f18e5e51f35dda5056538b9d0d0699c514ffc
GitHub-Last-Rev: 468e40586d31158dad1d06c8171bc4f857ec785c
GitHub-Pull-Request: golang/tools#523
Reviewed-on: https://go-review.googlesource.com/c/tools/+/613835
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/txtar/fs.go b/txtar/fs.go
index e37397e..fc8df12 100644
--- a/txtar/fs.go
+++ b/txtar/fs.go
@@ -10,6 +10,7 @@
"io"
"io/fs"
"path"
+ "slices"
"time"
)
@@ -152,10 +153,7 @@
return nil, err
}
if file, ok := file.(*openFile); ok {
- // TODO: use slices.Clone once x/tools has 1.21 available.
- cp := make([]byte, file.size)
- copy(cp, file.data)
- return cp, err
+ return slices.Clone(file.data), nil
}
return nil, &fs.PathError{Op: "read", Path: name, Err: fs.ErrInvalid}
}