diff options
author | Ian Cottrell <iancottrell@google.com> | 2020-04-03 23:06:57 -0400 |
---|---|---|
committer | Ian Cottrell <iancottrell@google.com> | 2020-04-08 13:20:38 +0000 |
commit | 6a75126720fd57301d36940869afbf88bbdda929 (patch) | |
tree | 2170697c32eb56503b920c45fcc3cb1ee6fd754b /internal/lsp/debug | |
parent | 46bd65c8538fb57593a8365bea5663a3239aee37 (diff) | |
download | golang-x-tools-6a75126720fd57301d36940869afbf88bbdda929.tar.gz |
internal/lsp: make tag iteration allocation-free
Change the tag iteration api to something less flexible
that allows for event iteration without allocation.
Change-Id: I212d45ebceea0183d1a61e6b611e0558649be60a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227301
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Diffstat (limited to 'internal/lsp/debug')
-rw-r--r-- | internal/lsp/debug/trace.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/internal/lsp/debug/trace.go b/internal/lsp/debug/trace.go index 1ea83aee5..0ae32c941 100644 --- a/internal/lsp/debug/trace.go +++ b/internal/lsp/debug/trace.go @@ -94,7 +94,7 @@ func (t *traces) ProcessEvent(ctx context.Context, ev event.Event, tags event.Ta ParentID: span.ParentID, Name: span.Name, Start: span.Start().At, - Tags: renderTags(span.Start().Tags()), + Tags: renderTags(span.Start()), } t.unfinished[span.ID] = td // and wire up parents if we have them @@ -124,7 +124,7 @@ func (t *traces) ProcessEvent(ctx context.Context, ev event.Event, tags event.Ta for i, event := range events { td.Events[i] = traceEvent{ Time: event.At, - Tags: renderTags(event.Tags()), + Tags: renderTags(event), } } @@ -170,10 +170,12 @@ func fillOffsets(td *traceData, start time.Time) { } } -func renderTags(tags event.TagIterator) string { +func renderTags(tags event.TagList) string { buf := &bytes.Buffer{} - for ; tags.Valid(); tags.Advance() { - fmt.Fprintf(buf, "%v ", tags.Tag()) + for index := 0; tags.Valid(index); index++ { + if tag := tags.Tag(index); tag.Valid() { + fmt.Fprintf(buf, "%v ", tag) + } } return buf.String() } |