1
0
mirror of https://github.com/golang/go synced 2024-11-26 07:38:00 -07:00

embed, testing/fstest: small optimization for ReadDir

Change-Id: If8dc6d917b55119b5662ce5b0b87328d220d684d
GitHub-Last-Rev: cc9a1d5a7e
GitHub-Pull-Request: golang/go#45388
Reviewed-on: https://go-review.googlesource.com/c/go/+/307250
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
徐志伟 2021-04-06 04:56:32 +00:00 committed by Tobias Klauser
parent 5d5f779db4
commit d6aa162f30
2 changed files with 6 additions and 6 deletions

View File

@ -386,15 +386,15 @@ func (d *openDir) Read([]byte) (int, error) {
func (d *openDir) ReadDir(count int) ([]fs.DirEntry, error) {
n := len(d.files) - d.offset
if count > 0 && n > count {
n = count
}
if n == 0 {
if count <= 0 {
return nil, nil
}
return nil, io.EOF
}
if count > 0 && n > count {
n = count
}
list := make([]fs.DirEntry, n)
for i := range list {
list[i] = &d.files[d.offset+i]

View File

@ -223,12 +223,12 @@ func (d *mapDir) Read(b []byte) (int, error) {
func (d *mapDir) ReadDir(count int) ([]fs.DirEntry, error) {
n := len(d.entry) - d.offset
if count > 0 && n > count {
n = count
}
if n == 0 && count > 0 {
return nil, io.EOF
}
if count > 0 && n > count {
n = count
}
list := make([]fs.DirEntry, n)
for i := range list {
list[i] = &d.entry[d.offset+i]