From c45f8ee075385b27a52ab721a15f1f6ee6ef95ee Mon Sep 17 00:00:00 2001 From: greatroar <@> Date: Sun, 18 Oct 2020 23:39:42 +0200 Subject: [PATCH] Replace restic.statT interface by concrete types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old time/op new time/op delta NodeFillUser-8 1.81µs ± 9% 1.50µs ± 5% -17.07% (p=0.000 n=19+20) NodeFromFileInfo-8 1.76µs ± 4% 1.49µs ± 6% -15.63% (p=0.000 n=20+19) name old alloc/op new alloc/op delta NodeFillUser-8 496B ± 0% 352B ± 0% -29.03% (p=0.000 n=20+20) NodeFromFileInfo-8 496B ± 0% 352B ± 0% -29.03% (p=0.000 n=20+20) name old allocs/op new allocs/op delta NodeFillUser-8 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.000 n=20+20) NodeFromFileInfo-8 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.000 n=20+20) --- internal/restic/node.go | 17 ++--------------- internal/restic/node_darwin.go | 6 +++--- internal/restic/node_freebsd.go | 6 +++--- internal/restic/node_linux.go | 7 +++---- internal/restic/node_netbsd.go | 6 +++--- internal/restic/node_openbsd.go | 6 +++--- internal/restic/node_solaris.go | 6 +++--- internal/restic/node_unix.go | 23 ++++++++++------------- internal/restic/node_windows.go | 30 +++++++++++++----------------- 9 files changed, 43 insertions(+), 64 deletions(-) diff --git a/internal/restic/node.go b/internal/restic/node.go index 7870459cb..42d240a5b 100644 --- a/internal/restic/node.go +++ b/internal/restic/node.go @@ -506,7 +506,7 @@ func (node Node) sameExtendedAttributes(other Node) bool { return true } -func (node *Node) fillUser(stat statT) { +func (node *Node) fillUser(stat *statT) { uid, gid := stat.uid(), stat.gid() node.UID, node.GID = uid, gid node.User = lookupUsername(uid) @@ -644,24 +644,11 @@ func (node *Node) fillExtendedAttributes(path string) error { return nil } -type statT interface { - dev() uint64 - ino() uint64 - nlink() uint64 - uid() uint32 - gid() uint32 - rdev() uint64 - size() int64 - atim() syscall.Timespec - mtim() syscall.Timespec - ctim() syscall.Timespec -} - func mkfifo(path string, mode uint32) (err error) { return mknod(path, mode|syscall.S_IFIFO, 0) } -func (node *Node) fillTimes(stat statT) { +func (node *Node) fillTimes(stat *statT) { ctim := stat.ctim() atim := stat.atim() node.ChangeTime = time.Unix(ctim.Unix()) diff --git a/internal/restic/node_darwin.go b/internal/restic/node_darwin.go index e8c2d3815..814def139 100644 --- a/internal/restic/node_darwin.go +++ b/internal/restic/node_darwin.go @@ -10,6 +10,6 @@ func (node Node) device() int { return int(node.Device) } -func (s statUnix) atim() syscall.Timespec { return s.Atimespec } -func (s statUnix) mtim() syscall.Timespec { return s.Mtimespec } -func (s statUnix) ctim() syscall.Timespec { return s.Ctimespec } +func (s statT) atim() syscall.Timespec { return s.Atimespec } +func (s statT) mtim() syscall.Timespec { return s.Mtimespec } +func (s statT) ctim() syscall.Timespec { return s.Ctimespec } diff --git a/internal/restic/node_freebsd.go b/internal/restic/node_freebsd.go index a8df07575..7439e3963 100644 --- a/internal/restic/node_freebsd.go +++ b/internal/restic/node_freebsd.go @@ -12,6 +12,6 @@ func (node Node) device() uint64 { return node.Device } -func (s statUnix) atim() syscall.Timespec { return s.Atimespec } -func (s statUnix) mtim() syscall.Timespec { return s.Mtimespec } -func (s statUnix) ctim() syscall.Timespec { return s.Ctimespec } +func (s statT) atim() syscall.Timespec { return s.Atimespec } +func (s statT) mtim() syscall.Timespec { return s.Mtimespec } +func (s statT) ctim() syscall.Timespec { return s.Ctimespec } diff --git a/internal/restic/node_linux.go b/internal/restic/node_linux.go index c2b1cc1ba..1e45a6ed2 100644 --- a/internal/restic/node_linux.go +++ b/internal/restic/node_linux.go @@ -7,7 +7,6 @@ import ( "golang.org/x/sys/unix" "github.com/restic/restic/internal/errors" - "github.com/restic/restic/internal/fs" ) @@ -36,6 +35,6 @@ func (node Node) device() int { return int(node.Device) } -func (s statUnix) atim() syscall.Timespec { return s.Atim } -func (s statUnix) mtim() syscall.Timespec { return s.Mtim } -func (s statUnix) ctim() syscall.Timespec { return s.Ctim } +func (s statT) atim() syscall.Timespec { return s.Atim } +func (s statT) mtim() syscall.Timespec { return s.Mtim } +func (s statT) ctim() syscall.Timespec { return s.Ctim } diff --git a/internal/restic/node_netbsd.go b/internal/restic/node_netbsd.go index 8c6626d96..052bf93be 100644 --- a/internal/restic/node_netbsd.go +++ b/internal/restic/node_netbsd.go @@ -10,9 +10,9 @@ func (node Node) device() int { return int(node.Device) } -func (s statUnix) atim() syscall.Timespec { return s.Atimespec } -func (s statUnix) mtim() syscall.Timespec { return s.Mtimespec } -func (s statUnix) ctim() syscall.Timespec { return s.Ctimespec } +func (s statT) atim() syscall.Timespec { return s.Atimespec } +func (s statT) mtim() syscall.Timespec { return s.Mtimespec } +func (s statT) ctim() syscall.Timespec { return s.Ctimespec } // Getxattr retrieves extended attribute data associated with path. func Getxattr(path, name string) ([]byte, error) { diff --git a/internal/restic/node_openbsd.go b/internal/restic/node_openbsd.go index 2a6548159..b10fd3b83 100644 --- a/internal/restic/node_openbsd.go +++ b/internal/restic/node_openbsd.go @@ -10,9 +10,9 @@ func (node Node) device() int { return int(node.Device) } -func (s statUnix) atim() syscall.Timespec { return s.Atim } -func (s statUnix) mtim() syscall.Timespec { return s.Mtim } -func (s statUnix) ctim() syscall.Timespec { return s.Ctim } +func (s statT) atim() syscall.Timespec { return s.Atim } +func (s statT) mtim() syscall.Timespec { return s.Mtim } +func (s statT) ctim() syscall.Timespec { return s.Ctim } // Getxattr retrieves extended attribute data associated with path. func Getxattr(path, name string) ([]byte, error) { diff --git a/internal/restic/node_solaris.go b/internal/restic/node_solaris.go index 2a6548159..b10fd3b83 100644 --- a/internal/restic/node_solaris.go +++ b/internal/restic/node_solaris.go @@ -10,9 +10,9 @@ func (node Node) device() int { return int(node.Device) } -func (s statUnix) atim() syscall.Timespec { return s.Atim } -func (s statUnix) mtim() syscall.Timespec { return s.Mtim } -func (s statUnix) ctim() syscall.Timespec { return s.Ctim } +func (s statT) atim() syscall.Timespec { return s.Atim } +func (s statT) mtim() syscall.Timespec { return s.Mtim } +func (s statT) ctim() syscall.Timespec { return s.Ctim } // Getxattr retrieves extended attribute data associated with path. func Getxattr(path, name string) ([]byte, error) { diff --git a/internal/restic/node_unix.go b/internal/restic/node_unix.go index eec07fc5a..f220725a9 100644 --- a/internal/restic/node_unix.go +++ b/internal/restic/node_unix.go @@ -10,23 +10,20 @@ import ( var mknod = syscall.Mknod var lchown = os.Lchown -type statUnix syscall.Stat_t +type statT syscall.Stat_t -func toStatT(i interface{}) (statT, bool) { - if i == nil { - return nil, false - } +func toStatT(i interface{}) (*statT, bool) { s, ok := i.(*syscall.Stat_t) if ok && s != nil { - return statUnix(*s), true + return (*statT)(s), true } return nil, false } -func (s statUnix) dev() uint64 { return uint64(s.Dev) } -func (s statUnix) ino() uint64 { return uint64(s.Ino) } -func (s statUnix) nlink() uint64 { return uint64(s.Nlink) } -func (s statUnix) uid() uint32 { return uint32(s.Uid) } -func (s statUnix) gid() uint32 { return uint32(s.Gid) } -func (s statUnix) rdev() uint64 { return uint64(s.Rdev) } -func (s statUnix) size() int64 { return int64(s.Size) } +func (s statT) dev() uint64 { return uint64(s.Dev) } +func (s statT) ino() uint64 { return uint64(s.Ino) } +func (s statT) nlink() uint64 { return uint64(s.Nlink) } +func (s statT) uid() uint32 { return uint32(s.Uid) } +func (s statT) gid() uint32 { return uint32(s.Gid) } +func (s statT) rdev() uint64 { return uint64(s.Rdev) } +func (s statT) size() int64 { return int64(s.Size) } diff --git a/internal/restic/node_windows.go b/internal/restic/node_windows.go index 28ebff6ae..fd0fc369c 100644 --- a/internal/restic/node_windows.go +++ b/internal/restic/node_windows.go @@ -42,40 +42,36 @@ func Setxattr(path, name string, data []byte) error { return nil } -type statWin syscall.Win32FileAttributeData +type statT syscall.Win32FileAttributeData -//ToStatT call the Windows system call Win32FileAttributeData. -func toStatT(i interface{}) (statT, bool) { - if i == nil { - return nil, false - } +func toStatT(i interface{}) (*statT, bool) { s, ok := i.(*syscall.Win32FileAttributeData) if ok && s != nil { - return statWin(*s), true + return (*statT)(s), true } return nil, false } -func (s statWin) dev() uint64 { return 0 } -func (s statWin) ino() uint64 { return 0 } -func (s statWin) nlink() uint64 { return 0 } -func (s statWin) uid() uint32 { return 0 } -func (s statWin) gid() uint32 { return 0 } -func (s statWin) rdev() uint64 { return 0 } +func (s statT) dev() uint64 { return 0 } +func (s statT) ino() uint64 { return 0 } +func (s statT) nlink() uint64 { return 0 } +func (s statT) uid() uint32 { return 0 } +func (s statT) gid() uint32 { return 0 } +func (s statT) rdev() uint64 { return 0 } -func (s statWin) size() int64 { +func (s statT) size() int64 { return int64(s.FileSizeLow) | (int64(s.FileSizeHigh) << 32) } -func (s statWin) atim() syscall.Timespec { +func (s statT) atim() syscall.Timespec { return syscall.NsecToTimespec(s.LastAccessTime.Nanoseconds()) } -func (s statWin) mtim() syscall.Timespec { +func (s statT) mtim() syscall.Timespec { return syscall.NsecToTimespec(s.LastWriteTime.Nanoseconds()) } -func (s statWin) ctim() syscall.Timespec { +func (s statT) ctim() syscall.Timespec { // Windows does not have the concept of a "change time" in the sense Unix uses it, so we're using the LastWriteTime here. return syscall.NsecToTimespec(s.LastWriteTime.Nanoseconds()) }