]> Cypherpunks repositories - gostls13.git/commitdiff
os: avoid calulating fileStat.path until it is needed
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 8 May 2017 02:49:04 +0000 (12:49 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Tue, 9 May 2017 04:47:47 +0000 (04:47 +0000)
This CL improves

on my Windows 7

name         old time/op    new time/op    delta
Readdirname    58.1µs ± 1%    58.1µs ± 0%     ~     (p=0.817 n=8+8)
Readdir        58.0µs ± 3%    57.8µs ± 0%     ~     (p=0.944 n=9+8)

name         old alloc/op   new alloc/op   delta
Readdirname    3.03kB ± 0%    2.84kB ± 0%   -6.33%  (p=0.000 n=10+10)
Readdir        3.00kB ± 0%    2.81kB ± 0%   -6.40%  (p=0.000 n=10+10)

name         old allocs/op  new allocs/op  delta
Readdirname      34.0 ± 0%      30.0 ± 0%  -11.76%  (p=0.000 n=10+10)
Readdir          33.0 ± 0%      29.0 ± 0%  -12.12%  (p=0.000 n=10+10)

on my Windows XP

name           old time/op    new time/op    delta
Readdirname-2    85.5µs ± 0%    84.0µs ± 0%   -1.83%  (p=0.000 n=10+10)
Readdir-2        84.6µs ± 0%    83.5µs ± 0%   -1.31%  (p=0.000 n=10+9)

name           old alloc/op   new alloc/op   delta
Readdirname-2    6.52kB ± 0%    5.66kB ± 0%  -13.25%  (p=0.000 n=10+10)
Readdir-2        6.39kB ± 0%    5.53kB ± 0%  -13.52%  (p=0.000 n=10+10)

name           old allocs/op  new allocs/op  delta
Readdirname-2      78.0 ± 0%      66.0 ± 0%  -15.38%  (p=0.000 n=10+10)
Readdir-2          77.0 ± 0%      65.0 ± 0%  -15.58%  (p=0.000 n=10+10)

Change-Id: I5d698eca86b8e94a46b6cfbd5947898b7b3fbdbd
Reviewed-on: https://go-review.googlesource.com/42894
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/os/dir_windows.go
src/os/types_windows.go

index 2e3046d73672c7dac3e0548f1e1cf2e7aade05bb..a738af276407b0a00f86ede5be54aa1ca0183f40 100644 (file)
@@ -56,7 +56,8 @@ func (file *File) readdir(n int) (fi []FileInfo, err error) {
                                FileSizeHigh:   d.FileSizeHigh,
                                FileSizeLow:    d.FileSizeLow,
                        },
-                       path: file.dirinfo.path + `\` + name,
+                       path:             file.dirinfo.path,
+                       appendNameToPath: true,
                }
                n--
                fi = append(fi, f)
index a0d6fa4e767f6d214f965befbd1ac9d049fa6b4e..01d6b62a16ec2d1c601958d9f7438874839e8d86 100644 (file)
@@ -18,10 +18,11 @@ type fileStat struct {
 
        // used to implement SameFile
        sync.Mutex
-       path  string
-       vol   uint32
-       idxhi uint32
-       idxlo uint32
+       path             string
+       vol              uint32
+       idxhi            uint32
+       idxlo            uint32
+       appendNameToPath bool
 }
 
 func (fs *fileStat) Size() int64 {
@@ -66,7 +67,13 @@ func (fs *fileStat) loadFileId() error {
                // already done
                return nil
        }
-       pathp, err := syscall.UTF16PtrFromString(fs.path)
+       var path string
+       if fs.appendNameToPath {
+               path = fs.path + `\` + fs.name
+       } else {
+               path = fs.path
+       }
+       pathp, err := syscall.UTF16PtrFromString(path)
        if err != nil {
                return err
        }