mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +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.
|
// Semantic ops.
|
||||||
case ops.TypeSemanticLabel:
|
case ops.TypeSemanticLabel:
|
||||||
lbl := encOp.Refs[0].(*string)
|
lbl := encOp.Refs[0].(string)
|
||||||
pc.semanticLabel(*lbl)
|
pc.semanticLabel(lbl)
|
||||||
case ops.TypeSemanticDesc:
|
case ops.TypeSemanticDesc:
|
||||||
desc := encOp.Refs[0].(*string)
|
desc := encOp.Refs[0].(string)
|
||||||
pc.semanticDesc(*desc)
|
pc.semanticDesc(desc)
|
||||||
case ops.TypeSemanticClass:
|
case ops.TypeSemanticClass:
|
||||||
class := semantic.ClassOp(encOp.Data[1])
|
class := semantic.ClassOp(encOp.Data[1])
|
||||||
pc.semanticClass(class)
|
pc.semanticClass(class)
|
||||||
|
|||||||
@@ -40,14 +40,12 @@ type SelectedOp bool
|
|||||||
type DisabledOp bool
|
type DisabledOp bool
|
||||||
|
|
||||||
func (l LabelOp) Add(o *op.Ops) {
|
func (l LabelOp) Add(o *op.Ops) {
|
||||||
s := string(l)
|
data := ops.Write1(&o.Internal, ops.TypeSemanticLabelLen, string(l))
|
||||||
data := ops.Write1(&o.Internal, ops.TypeSemanticLabelLen, &s)
|
|
||||||
data[0] = byte(ops.TypeSemanticLabel)
|
data[0] = byte(ops.TypeSemanticLabel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d DescriptionOp) Add(o *op.Ops) {
|
func (d DescriptionOp) Add(o *op.Ops) {
|
||||||
s := string(d)
|
data := ops.Write1(&o.Internal, ops.TypeSemanticDescLen, string(d))
|
||||||
data := ops.Write1(&o.Internal, ops.TypeSemanticDescLen, &s)
|
|
||||||
data[0] = byte(ops.TypeSemanticDesc)
|
data[0] = byte(ops.TypeSemanticDesc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user