Skip to content

Commit a6bf59b

Browse files
committed
Memoize node size.
1 parent 5e366a8 commit a6bf59b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

node/root.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Node interface {
1616
type node struct {
1717
file os.FileInfo
1818
name string
19+
size int
1920
}
2021

2122
// Fetch - Fetch nodes in currently directory
@@ -26,7 +27,7 @@ func Fetch() []Node {
2627
nodes := make([]Node, len(files))
2728

2829
for i:=0; i<len(files); i++ {
29-
nodes[i] = node{files[i], ""}
30+
nodes[i] = node{files[i], "", 0}
3031
}
3132

3233
return nodes
@@ -46,5 +47,7 @@ func (n node) Name() string {
4647
}
4748

4849
func (n node) Size() int {
49-
return len([]rune(n.Name()))
50+
if n.size != 0 { return n.size }
51+
n.size = len([]rune(n.Name()))
52+
return n.size
5053
}

0 commit comments

Comments
 (0)