forked from joejulian/gio
internal/ops: optimize Decode
Using clean struct creation creates a lot of temporary variables in assembly. Inline the assignments, which generates less code. Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
+6
-15
@@ -168,21 +168,12 @@ func (op *ClipOp) Decode(data []byte) {
|
||||
}
|
||||
data = data[:TypeClipLen]
|
||||
bo := binary.LittleEndian
|
||||
r := image.Rectangle{
|
||||
Min: image.Point{
|
||||
X: int(int32(bo.Uint32(data[1:]))),
|
||||
Y: int(int32(bo.Uint32(data[5:]))),
|
||||
},
|
||||
Max: image.Point{
|
||||
X: int(int32(bo.Uint32(data[9:]))),
|
||||
Y: int(int32(bo.Uint32(data[13:]))),
|
||||
},
|
||||
}
|
||||
*op = ClipOp{
|
||||
Bounds: r,
|
||||
Outline: data[17] == 1,
|
||||
Shape: Shape(data[18]),
|
||||
}
|
||||
op.Bounds.Min.X = int(int32(bo.Uint32(data[1:])))
|
||||
op.Bounds.Min.Y = int(int32(bo.Uint32(data[5:])))
|
||||
op.Bounds.Max.X = int(int32(bo.Uint32(data[9:])))
|
||||
op.Bounds.Max.Y = int(int32(bo.Uint32(data[13:])))
|
||||
op.Outline = data[17] == 1
|
||||
op.Shape = Shape(data[18])
|
||||
}
|
||||
|
||||
func Reset(o *Ops) {
|
||||
|
||||
+8
-19
@@ -165,14 +165,8 @@ func (op *opMacroDef) decode(data []byte) {
|
||||
}
|
||||
bo := binary.LittleEndian
|
||||
data = data[:TypeMacroLen]
|
||||
dataIdx := int(int32(bo.Uint32(data[1:])))
|
||||
refsIdx := int(int32(bo.Uint32(data[5:])))
|
||||
*op = opMacroDef{
|
||||
endpc: PC{
|
||||
data: dataIdx,
|
||||
refs: refsIdx,
|
||||
},
|
||||
}
|
||||
op.endpc.data = int(int32(bo.Uint32(data[1:])))
|
||||
op.endpc.refs = int(int32(bo.Uint32(data[5:])))
|
||||
}
|
||||
|
||||
func (m *macroOp) decode(data []byte, refs []interface{}) {
|
||||
@@ -181,15 +175,10 @@ func (m *macroOp) decode(data []byte, refs []interface{}) {
|
||||
}
|
||||
bo := binary.LittleEndian
|
||||
data = data[:TypeCallLen]
|
||||
*m = macroOp{
|
||||
ops: refs[0].(*Ops),
|
||||
start: PC{
|
||||
data: int(int32(bo.Uint32(data[1:]))),
|
||||
refs: int(int32(bo.Uint32(data[5:]))),
|
||||
},
|
||||
end: PC{
|
||||
data: int(int32(bo.Uint32(data[9:]))),
|
||||
refs: int(int32(bo.Uint32(data[13:]))),
|
||||
},
|
||||
}
|
||||
|
||||
m.ops = refs[0].(*Ops)
|
||||
m.start.data = int(int32(bo.Uint32(data[1:])))
|
||||
m.start.refs = int(int32(bo.Uint32(data[5:])))
|
||||
m.end.data = int(int32(bo.Uint32(data[9:])))
|
||||
m.end.refs = int(int32(bo.Uint32(data[13:])))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user