summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-30 00:47:07 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-30 00:47:07 +0200
commitd7411d8e5a0a5f974c2a8a5fe52d4265c4b951b8 (patch)
treed74670488527c321f6512289c9dfa77b366643c7
parent3dfe287f7c89c7a746b60d69b8dd6c76c58a3157 (diff)
less allocations
-rw-r--r--go/react/react.go12
1 files changed, 5 insertions, 7 deletions
diff --git a/go/react/react.go b/go/react/react.go
index 3285f49..42a0737 100644
--- a/go/react/react.go
+++ b/go/react/react.go
@@ -5,13 +5,11 @@ const testVersion = 4
/* reactor */
type reactor struct {
- cells map[*compuCell]struct{}
+ cells []*compuCell
}
func New() Reactor {
- return &reactor{
- cells: make(map[*compuCell]struct{}),
- }
+ return &reactor{}
}
func (r *reactor) CreateCompute1(c Cell, f func(int) int) ComputeCell {
@@ -28,7 +26,7 @@ func (r *reactor) CreateCompute1(c Cell, f func(int) int) ComputeCell {
}
return v
}
- r.cells[cc] = struct{}{}
+ r.cells = append(r.cells, cc)
return cc
}
@@ -46,7 +44,7 @@ func (r *reactor) CreateCompute2(c1, c2 Cell, f func(int, int) int) ComputeCell
}
return v
}
- r.cells[cc] = struct{}{}
+ r.cells = append(r.cells, cc)
return cc
}
@@ -67,7 +65,7 @@ type inputCell struct {
func (c *inputCell) SetValue(i int) {
if c.value != i {
c.value = i
- for cc := range c.cells {
+ for _, cc := range c.cells {
cc.eval()
}
}