mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
Many operations do not pass refs to Write. Similarly adding
...interface{} requires constructing a slice, which is slow.
This cuts about 100ns from RRect and Border benchmark.
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
+1
-1
@@ -113,7 +113,7 @@ func (m Modifiers) Contain(m2 Modifiers) bool {
|
||||
}
|
||||
|
||||
func (h InputOp) Add(o *op.Ops) {
|
||||
data := o.Write(opconst.TypeKeyInputLen, h.Tag)
|
||||
data := o.Write1(opconst.TypeKeyInputLen, h.Tag)
|
||||
data[0] = byte(opconst.TypeKeyInput)
|
||||
if h.Focus {
|
||||
data[1] = 1
|
||||
|
||||
@@ -159,7 +159,7 @@ func (op AreaOp) Add(o *op.Ops) {
|
||||
}
|
||||
|
||||
func (h InputOp) Add(o *op.Ops) {
|
||||
data := o.Write(opconst.TypePointerInputLen, h.Tag)
|
||||
data := o.Write1(opconst.TypePointerInputLen, h.Tag)
|
||||
data[0] = byte(opconst.TypePointerInput)
|
||||
if h.Grab {
|
||||
data[1] = 1
|
||||
|
||||
@@ -24,7 +24,7 @@ type Event struct {
|
||||
}
|
||||
|
||||
func (p Op) Add(o *op.Ops) {
|
||||
data := o.Write(opconst.TypeProfileLen, p.Tag)
|
||||
data := o.Write1(opconst.TypeProfileLen, p.Tag)
|
||||
data[0] = byte(opconst.TypeProfile)
|
||||
}
|
||||
|
||||
|
||||
@@ -192,9 +192,22 @@ func (o *Ops) Version() int {
|
||||
}
|
||||
|
||||
// Write is for internal use only.
|
||||
func (o *Ops) Write(n int, refs ...interface{}) []byte {
|
||||
func (o *Ops) Write(n int) []byte {
|
||||
o.data = append(o.data, make([]byte, n)...)
|
||||
o.refs = append(o.refs, refs...)
|
||||
return o.data[len(o.data)-n:]
|
||||
}
|
||||
|
||||
// Write1 is for internal use only.
|
||||
func (o *Ops) Write1(n int, ref1 interface{}) []byte {
|
||||
o.data = append(o.data, make([]byte, n)...)
|
||||
o.refs = append(o.refs, ref1)
|
||||
return o.data[len(o.data)-n:]
|
||||
}
|
||||
|
||||
// Write2 is for internal use only.
|
||||
func (o *Ops) Write2(n int, ref1, ref2 interface{}) []byte {
|
||||
o.data = append(o.data, make([]byte, n)...)
|
||||
o.refs = append(o.refs, ref1, ref2)
|
||||
return o.data[len(o.data)-n:]
|
||||
}
|
||||
|
||||
@@ -244,7 +257,7 @@ func (c CallOp) Add(o *Ops) {
|
||||
if c.ops == nil {
|
||||
return
|
||||
}
|
||||
data := o.Write(opconst.TypeCallLen, c.ops)
|
||||
data := o.Write1(opconst.TypeCallLen, c.ops)
|
||||
data[0] = byte(opconst.TypeCall)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], uint32(c.pc.data))
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ func (i ImageOp) Add(o *op.Ops) {
|
||||
}.Add(o)
|
||||
return
|
||||
}
|
||||
data := o.Write(opconst.TypeImageLen, i.src, i.handle)
|
||||
data := o.Write2(opconst.TypeImageLen, i.src, i.handle)
|
||||
data[0] = byte(opconst.TypeImage)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user