Skip to content

Commit 5cb6eeb

Browse files
Stavrospanakakistimothy-king
authored andcommittedSep 17, 2024·
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: 468e405 GitHub-Pull-Request: #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>
1 parent e603756 commit 5cb6eeb

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed
 

‎txtar/fs.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io"
1111
"io/fs"
1212
"path"
13+
"slices"
1314
"time"
1415
)
1516

@@ -152,10 +153,7 @@ func (fsys *filesystem) ReadFile(name string) ([]byte, error) {
152153
return nil, err
153154
}
154155
if file, ok := file.(*openFile); ok {
155-
// TODO: use slices.Clone once x/tools has 1.21 available.
156-
cp := make([]byte, file.size)
157-
copy(cp, file.data)
158-
return cp, err
156+
return slices.Clone(file.data), nil
159157
}
160158
return nil, &fs.PathError{Op: "read", Path: name, Err: fs.ErrInvalid}
161159
}

0 commit comments

Comments
 (0)
Please sign in to comment.