Skip to content

Commit

Permalink
txtar: use slices.Clone instead of copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Stavrospanakakis committed Sep 17, 2024
1 parent 765ea95 commit 0441413
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 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,9 +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)
cp := slices.Clone(file.data)
return cp, err
}
return nil, &fs.PathError{Op: "read", Path: name, Err: fs.ErrInvalid}
Expand Down

0 comments on commit 0441413

Please sign in to comment.