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 <dominik@honnef.co>
This commit is contained in:
Dominik Honnef
2023-04-11 03:56:23 +02:00
committed by Elias Naur
parent 6937a5dd1f
commit b6e0376ad2
2 changed files with 6 additions and 8 deletions
+2 -4
View File
@@ -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)
}