From 08e47b4a9eb0091d823dca411ad09001dbca4c4a Mon Sep 17 00:00:00 2001 From: kortschak Date: Thu, 21 Aug 2014 15:23:30 +0930 Subject: [PATCH] Do tagger copying with less iteration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes minimal difference to the benchmarks in cayley_test.go (a variable ±5% on the bigger cases). --- graph/iterator.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/graph/iterator.go b/graph/iterator.go index ca17cb5..83f1999 100644 --- a/graph/iterator.go +++ b/graph/iterator.go @@ -51,14 +51,16 @@ func (t *Tagger) Fixed() map[string]Value { } func (t *Tagger) CopyFrom(src Iterator) { - for _, tag := range src.Tagger().Tags() { - t.Add(tag) - } + st := src.Tagger() - for k, v := range src.Tagger().Fixed() { - t.AddFixed(k, v) - } + t.tags = append(t.tags, st.tags...) + if t.fixedTags == nil { + t.fixedTags = make(map[string]Value, len(st.fixedTags)) + } + for k, v := range st.fixedTags { + t.fixedTags[k] = v + } } type Iterator interface {