From d7411d8e5a0a5f974c2a8a5fe52d4265c4b951b8 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 30 Aug 2016 00:47:07 +0200 Subject: less allocations --- go/react/react.go | 12 +++++------- 1 file 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() } } -- cgit v1.2.3