Skip to content

Commit

Permalink
txtar: use slices.Clone instead of copy
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Stavrospanakakis authored and timothy-king committed Sep 17, 2024
1 parent e603756 commit 5cb6eeb
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions txtar/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"io/fs"
"path"
"slices"
"time"
)

Expand Down Expand Up @@ -152,10 +153,7 @@ func (fsys *filesystem) ReadFile(name string) ([]byte, error) {
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}
}
Expand Down

0 comments on commit 5cb6eeb

Please sign in to comment.