diff options
| author | Taru Karttunen <taruti@taruti.net> | 2015-10-28 12:58:58 +0200 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2015-10-30 19:47:55 +0000 |
| commit | f5f480e1df6b394ebc71eb3c1ba2b4c91c232425 (patch) | |
| tree | 61e1a0544abcb5227cf14cbdafd3c1f52a08f8be /src/os/stat_linux.go | |
| parent | a21b4bca0c82098f3a445d663365c9afea8fa699 (diff) | |
| download | go-f5f480e1df6b394ebc71eb3c1ba2b4c91c232425.tar.xz | |
os: reduce allocations in Readdir on unix
Include syscall.Stat_t on unix to the
unexported fileStat structure rather than
accessing it though an interface.
Additionally add a benchmark for Readdir
(and Readdirnames).
Tested on linux, freebsd, netbsd, openbsd
darwin, solaris, does not touch windows
stuff. Does not change the API, as
discussed on golang-dev.
E.g. on linux/amd64 with a directory of 65 files:
benchmark old ns/op new ns/op delta
BenchmarkReaddir-4 67774 66225 -2.29%
benchmark old allocs new allocs delta
BenchmarkReaddir-4 334 269 -19.46%
benchmark old bytes new bytes delta
BenchmarkReaddir-4 25208 24168 -4.13%
Change-Id: I44ef72a04ad7055523a980f29aa11122040ae8fe
Reviewed-on: https://go-review.googlesource.com/16423
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/os/stat_linux.go')
| -rw-r--r-- | src/os/stat_linux.go | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/os/stat_linux.go b/src/os/stat_linux.go index 605c1d9b64..69e63230eb 100644 --- a/src/os/stat_linux.go +++ b/src/os/stat_linux.go @@ -9,21 +9,12 @@ import ( "time" ) -func sameFile(fs1, fs2 *fileStat) bool { - stat1 := fs1.sys.(*syscall.Stat_t) - stat2 := fs2.sys.(*syscall.Stat_t) - return stat1.Dev == stat2.Dev && stat1.Ino == stat2.Ino -} - -func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo { - fs := &fileStat{ - name: basename(name), - size: int64(st.Size), - modTime: timespecToTime(st.Mtim), - sys: st, - } - fs.mode = FileMode(st.Mode & 0777) - switch st.Mode & syscall.S_IFMT { +func fillFileStatFromSys(fs *fileStat, name string) { + fs.name = basename(name) + fs.size = int64(fs.sys.Size) + fs.modTime = timespecToTime(fs.sys.Mtim) + fs.mode = FileMode(fs.sys.Mode & 0777) + switch fs.sys.Mode & syscall.S_IFMT { case syscall.S_IFBLK: fs.mode |= ModeDevice case syscall.S_IFCHR: @@ -39,16 +30,15 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo { case syscall.S_IFSOCK: fs.mode |= ModeSocket } - if st.Mode&syscall.S_ISGID != 0 { + if fs.sys.Mode&syscall.S_ISGID != 0 { fs.mode |= ModeSetgid } - if st.Mode&syscall.S_ISUID != 0 { + if fs.sys.Mode&syscall.S_ISUID != 0 { fs.mode |= ModeSetuid } - if st.Mode&syscall.S_ISVTX != 0 { + if fs.sys.Mode&syscall.S_ISVTX != 0 { fs.mode |= ModeSticky } - return fs } func timespecToTime(ts syscall.Timespec) time.Time { |
