Skip to content

Commit 17dd748

Browse files
Merge pull request ardanlabs#382 from tebeka/caching
A simpler way to create linked list
2 parents 75ef582 + e8af807 commit 17dd748

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

topics/go/testing/benchmarks/caching/caching.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,17 @@ type data struct {
2727
var list *data
2828

2929
func init() {
30-
var last *data
31-
3230
// Create a link list with the same number of elements.
3331
for row := 0; row < rows; row++ {
3432
for col := 0; col < cols; col++ {
3533

36-
// Create a new node and link it in.
37-
var d data
38-
if list == nil {
39-
list = &d
40-
}
41-
if last != nil {
42-
last.p = &d
43-
}
44-
last = &d
34+
// Create a new node and link it backwards.
35+
list = &data{p: list}
4536

4637
// Add a value to all even elements.
4738
if row%2 == 0 {
4839
matrix[row][col] = 0xFF
49-
d.v = 0xFF
40+
list.v = 0xFF
5041
}
5142
}
5243
}

0 commit comments

Comments
 (0)