]> Cypherpunks repositories - gostls13.git/commitdiff
embed, testing/fstest: small optimization for ReadDir
author徐志伟 <juwan.xu@qq.com>
Tue, 6 Apr 2021 04:56:32 +0000 (04:56 +0000)
committerTobias Klauser <tobias.klauser@gmail.com>
Wed, 7 Apr 2021 09:59:58 +0000 (09:59 +0000)
Change-Id: If8dc6d917b55119b5662ce5b0b87328d220d684d
GitHub-Last-Rev: cc9a1d5a7e2599ee7f98c61d35b2450b9b6a92c3
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>

src/embed/embed.go
src/testing/fstest/mapfs.go

index 7f2719d2a78062ab9749f17fe67c9ea8f4d7ab64..851cc216fca2eba28e5898486cc4488113df7967 100644 (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]
index a5d4a23faca4c31797858c3fe24f5fa1903ef20a..9fef2f4696ec7944acc891eb3c69e86a3f376139 100644 (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]