mirror of
https://github.com/golang/go
synced 2024-11-26 21:31:32 -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:
parent
5d5f779db4
commit
d6aa162f30
@ -386,15 +386,15 @@ func (d *openDir) Read([]byte) (int, error) {
|
|||||||
|
|
||||||
func (d *openDir) ReadDir(count int) ([]fs.DirEntry, error) {
|
func (d *openDir) ReadDir(count int) ([]fs.DirEntry, error) {
|
||||||
n := len(d.files) - d.offset
|
n := len(d.files) - d.offset
|
||||||
if count > 0 && n > count {
|
|
||||||
n = count
|
|
||||||
}
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
if count <= 0 {
|
if count <= 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return nil, io.EOF
|
return nil, io.EOF
|
||||||
}
|
}
|
||||||
|
if count > 0 && n > count {
|
||||||
|
n = count
|
||||||
|
}
|
||||||
list := make([]fs.DirEntry, n)
|
list := make([]fs.DirEntry, n)
|
||||||
for i := range list {
|
for i := range list {
|
||||||
list[i] = &d.files[d.offset+i]
|
list[i] = &d.files[d.offset+i]
|
||||||
|
@ -223,12 +223,12 @@ func (d *mapDir) Read(b []byte) (int, error) {
|
|||||||
|
|
||||||
func (d *mapDir) ReadDir(count int) ([]fs.DirEntry, error) {
|
func (d *mapDir) ReadDir(count int) ([]fs.DirEntry, error) {
|
||||||
n := len(d.entry) - d.offset
|
n := len(d.entry) - d.offset
|
||||||
if count > 0 && n > count {
|
|
||||||
n = count
|
|
||||||
}
|
|
||||||
if n == 0 && count > 0 {
|
if n == 0 && count > 0 {
|
||||||
return nil, io.EOF
|
return nil, io.EOF
|
||||||
}
|
}
|
||||||
|
if count > 0 && n > count {
|
||||||
|
n = count
|
||||||
|
}
|
||||||
list := make([]fs.DirEntry, n)
|
list := make([]fs.DirEntry, n)
|
||||||
for i := range list {
|
for i := range list {
|
||||||
list[i] = &d.entry[d.offset+i]
|
list[i] = &d.entry[d.offset+i]
|
||||||
|
Loading…
Reference in New Issue
Block a user