10000 fs walk: inline visiting callback (micro-optimize) · NVIDIA/aistore@a2f0dd2 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit a2f0dd2

Browse files
committed
fs walk: inline visiting callback (micro-optimize)
* avoid heap allocation from the closure Signed-off-by: Alex Aizman <alex.aizman@gmail.com>
1 parent f90fd6e commit a2f0dd2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

fs/walk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type (
4545
}
4646

4747
errCallbackWrapper struct {
48-
counter atomic.Int64
48+
counter atomic.Int64 // (soft errors)
4949
}
5050

5151
walkDirWrapper struct {

fs/walk_godir.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ func (ew *errCallbackWrapper) PathErrToAction(_ string, err error) godirwalk.Err
4444
return godirwalk.Halt
4545
}
4646

47+
func (opts *WalkOpts) cb(fqn string, de *godirwalk.Dirent) error {
48+
return opts.Callback(fqn, de)
49+
}
50+
4751
func (godir) walk(fqns []string, opts *WalkOpts) error {
4852
var (
4953
err error
@@ -52,9 +56,7 @@ func (godir) walk(fqns []string, opts *WalkOpts) error {
5256
scratch, slab := memsys.PageMM().AllocSize(memsys.DefaultBufSize)
5357
gOpts := &godirwalk.Options{
5458
ErrorCallback: ew.PathErrToAction, // "halts the walk" or "skips the node" (detailed comment above)
55-
Callback: func(fqn string, de *godirwalk.Dirent) error { // TODO -- FIXME: ref
56-
return opts.Callback(fqn, de)
57-
},
59+
Callback: opts.cb,
5860
Unsorted: !opts.Sorted,
5961
ScratchBuffer: scratch,
6062
}

0 commit comments

Comments
 (0)
0