From b6e0376ad2febfbced42ff9e5edbcaf7b4a8ad94 Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Tue, 11 Apr 2023 03:56:23 +0200 Subject: [PATCH] io/semantic: avoid unnecessary pointer indirection Putting a string in an interface value has to (normally) heap allocate the string header and string. However, putting the address of a local string variable in an interface value has the same effect, as this causes the local variable to escape to the heap. Signed-off-by: Dominik Honnef --- io/router/router.go | 8 ++++---- io/semantic/semantic.go | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/io/router/router.go b/io/router/router.go index e3b3be8d..3f4a40aa 100644 --- a/io/router/router.go +++ b/io/router/router.go @@ -538,11 +538,11 @@ func (q *Router) collect() { // Semantic ops. case ops.TypeSemanticLabel: - lbl := encOp.Refs[0].(*string) - pc.semanticLabel(*lbl) + lbl := encOp.Refs[0].(string) + pc.semanticLabel(lbl) case ops.TypeSemanticDesc: - desc := encOp.Refs[0].(*string) - pc.semanticDesc(*desc) + desc := encOp.Refs[0].(string) + pc.semanticDesc(desc) case ops.TypeSemanticClass: class := semantic.ClassOp(encOp.Data[1]) pc.semanticClass(class) diff --git a/io/semantic/semantic.go b/io/semantic/semantic.go index 7499fc8a..86e2b20e 100644 --- a/io/semantic/semantic.go +++ b/io/semantic/semantic.go @@ -40,14 +40,12 @@ type SelectedOp bool type DisabledOp bool func (l LabelOp) Add(o *op.Ops) { - s := string(l) - data := ops.Write1(&o.Internal, ops.TypeSemanticLabelLen, &s) + data := ops.Write1(&o.Internal, ops.TypeSemanticLabelLen, string(l)) data[0] = byte(ops.TypeSemanticLabel) } func (d DescriptionOp) Add(o *op.Ops) { - s := string(d) - data := ops.Write1(&o.Internal, ops.TypeSemanticDescLen, &s) + data := ops.Write1(&o.Internal, ops.TypeSemanticDescLen, string(d)) data[0] = byte(ops.TypeSemanticDesc) } -- 2.38.5