mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
committed by
Elias Naur
parent
6937a5dd1f
commit
b6e0376ad2
+4
-4
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user