mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +00:00
internal/ops: use single table for OpType
Size and NumRefs are always used together, so consolidate info to a single table to avoid two separate lookups. Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
+52
-62
@@ -381,74 +381,64 @@ func DecodeLoad(data []byte) int {
|
|||||||
return int(bo.Uint32(data[1:]))
|
return int(bo.Uint32(data[1:]))
|
||||||
}
|
}
|
||||||
|
|
||||||
var opSize = [0x100]byte{
|
type opProp struct {
|
||||||
TypeMacro: TypeMacroLen,
|
Size byte
|
||||||
TypeCall: TypeCallLen,
|
NumRefs byte
|
||||||
TypeDefer: TypeDeferLen,
|
}
|
||||||
TypePushTransform: TypePushTransformLen,
|
|
||||||
TypeTransform: TypeTransformLen,
|
var opProps = [0x100]opProp{
|
||||||
TypePopTransform: TypePopTransformLen,
|
TypeMacro: {Size: TypeMacroLen, NumRefs: 0},
|
||||||
TypeInvalidate: TypeRedrawLen,
|
TypeCall: {Size: TypeCallLen, NumRefs: 1},
|
||||||
TypeImage: TypeImageLen,
|
TypeDefer: {Size: TypeDeferLen, NumRefs: 0},
|
||||||
TypePaint: TypePaintLen,
|
TypePushTransform: {Size: TypePushTransformLen, NumRefs: 0},
|
||||||
TypeColor: TypeColorLen,
|
TypeTransform: {Size: TypeTransformLen, NumRefs: 0},
|
||||||
TypeLinearGradient: TypeLinearGradientLen,
|
TypePopTransform: {Size: TypePopTransformLen, NumRefs: 0},
|
||||||
TypePass: TypePassLen,
|
TypeInvalidate: {Size: TypeRedrawLen, NumRefs: 0},
|
||||||
TypePopPass: TypePopPassLen,
|
TypeImage: {Size: TypeImageLen, NumRefs: 2},
|
||||||
TypePointerInput: TypePointerInputLen,
|
TypePaint: {Size: TypePaintLen, NumRefs: 0},
|
||||||
TypeClipboardRead: TypeClipboardReadLen,
|
TypeColor: {Size: TypeColorLen, NumRefs: 0},
|
||||||
TypeClipboardWrite: TypeClipboardWriteLen,
|
TypeLinearGradient: {Size: TypeLinearGradientLen, NumRefs: 0},
|
||||||
TypeSource: TypeSourceLen,
|
TypePass: {Size: TypePassLen, NumRefs: 0},
|
||||||
TypeTarget: TypeTargetLen,
|
TypePopPass: {Size: TypePopPassLen, NumRefs: 0},
|
||||||
TypeOffer: TypeOfferLen,
|
TypePointerInput: {Size: TypePointerInputLen, NumRefs: 1},
|
||||||
TypeKeyInput: TypeKeyInputLen,
|
TypeClipboardRead: {Size: TypeClipboardReadLen, NumRefs: 1},
|
||||||
TypeKeyFocus: TypeKeyFocusLen,
|
TypeClipboardWrite: {Size: TypeClipboardWriteLen, NumRefs: 1},
|
||||||
TypeKeySoftKeyboard: TypeKeySoftKeyboardLen,
|
TypeSource: {Size: TypeSourceLen, NumRefs: 2},
|
||||||
TypeSave: TypeSaveLen,
|
TypeTarget: {Size: TypeTargetLen, NumRefs: 2},
|
||||||
TypeLoad: TypeLoadLen,
|
TypeOffer: {Size: TypeOfferLen, NumRefs: 3},
|
||||||
TypeAux: TypeAuxLen,
|
TypeKeyInput: {Size: TypeKeyInputLen, NumRefs: 2},
|
||||||
TypeClip: TypeClipLen,
|
TypeKeyFocus: {Size: TypeKeyFocusLen, NumRefs: 1},
|
||||||
TypePopClip: TypePopClipLen,
|
TypeKeySoftKeyboard: {Size: TypeKeySoftKeyboardLen, NumRefs: 0},
|
||||||
TypeProfile: TypeProfileLen,
|
TypeSave: {Size: TypeSaveLen, NumRefs: 0},
|
||||||
TypeCursor: TypeCursorLen,
|
TypeLoad: {Size: TypeLoadLen, NumRefs: 0},
|
||||||
TypePath: TypePathLen,
|
TypeAux: {Size: TypeAuxLen, NumRefs: 0},
|
||||||
TypeStroke: TypeStrokeLen,
|
TypeClip: {Size: TypeClipLen, NumRefs: 0},
|
||||||
TypeSemanticLabel: TypeSemanticLabelLen,
|
TypePopClip: {Size: TypePopClipLen, NumRefs: 0},
|
||||||
TypeSemanticDesc: TypeSemanticDescLen,
|
TypeProfile: {Size: TypeProfileLen, NumRefs: 1},
|
||||||
TypeSemanticClass: TypeSemanticClassLen,
|
TypeCursor: {Size: TypeCursorLen, NumRefs: 0},
|
||||||
TypeSemanticSelected: TypeSemanticSelectedLen,
|
TypePath: {Size: TypePathLen, NumRefs: 0},
|
||||||
TypeSemanticDisabled: TypeSemanticDisabledLen,
|
TypeStroke: {Size: TypeStrokeLen, NumRefs: 0},
|
||||||
TypeSnippet: TypeSnippetLen,
|
TypeSemanticLabel: {Size: TypeSemanticLabelLen, NumRefs: 1},
|
||||||
TypeSelection: TypeSelectionLen,
|
TypeSemanticDesc: {Size: TypeSemanticDescLen, NumRefs: 1},
|
||||||
TypeActionInput: TypeActionInputLen,
|
TypeSemanticClass: {Size: TypeSemanticClassLen, NumRefs: 0},
|
||||||
|
TypeSemanticSelected: {Size: TypeSemanticSelectedLen, NumRefs: 0},
|
||||||
|
TypeSemanticDisabled: {Size: TypeSemanticDisabledLen, NumRefs: 0},
|
||||||
|
TypeSnippet: {Size: TypeSnippetLen, NumRefs: 2},
|
||||||
|
TypeSelection: {Size: TypeSelectionLen, NumRefs: 1},
|
||||||
|
TypeActionInput: {Size: TypeActionInputLen, NumRefs: 0},
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t OpType) props() (size, numRefs int) {
|
||||||
|
v := opProps[t]
|
||||||
|
return int(v.Size), int(v.NumRefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t OpType) Size() int {
|
func (t OpType) Size() int {
|
||||||
return int(opSize[t])
|
return int(opProps[t].Size)
|
||||||
}
|
|
||||||
|
|
||||||
var opNumRefs = [0x100]byte{
|
|
||||||
TypeKeyFocus: 1,
|
|
||||||
TypePointerInput: 1,
|
|
||||||
TypeProfile: 1,
|
|
||||||
TypeCall: 1,
|
|
||||||
TypeClipboardRead: 1,
|
|
||||||
TypeClipboardWrite: 1,
|
|
||||||
TypeSemanticLabel: 1,
|
|
||||||
TypeSemanticDesc: 1,
|
|
||||||
TypeSelection: 1,
|
|
||||||
|
|
||||||
TypeKeyInput: 2,
|
|
||||||
TypeImage: 2,
|
|
||||||
TypeSource: 2,
|
|
||||||
TypeTarget: 2,
|
|
||||||
TypeSnippet: 2,
|
|
||||||
|
|
||||||
TypeOffer: 3,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t OpType) NumRefs() int {
|
func (t OpType) NumRefs() int {
|
||||||
return int(opNumRefs[t])
|
return int(opProps[t].NumRefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t OpType) String() string {
|
func (t OpType) String() string {
|
||||||
|
|||||||
@@ -54,9 +54,10 @@ type opMacroDef struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pc PC) Add(op OpType) PC {
|
func (pc PC) Add(op OpType) PC {
|
||||||
|
size, numRefs := op.props()
|
||||||
return PC{
|
return PC{
|
||||||
data: pc.data + op.Size(),
|
data: pc.data + size,
|
||||||
refs: pc.refs + op.NumRefs(),
|
refs: pc.refs + numRefs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,8 +105,7 @@ func (r *Reader) Decode() (EncodedOp, bool) {
|
|||||||
}
|
}
|
||||||
key := Key{ops: r.ops, pc: r.pc.data, version: r.ops.version}
|
key := Key{ops: r.ops, pc: r.pc.data, version: r.ops.version}
|
||||||
t := OpType(data[0])
|
t := OpType(data[0])
|
||||||
n := t.Size()
|
n, nrefs := t.props()
|
||||||
nrefs := t.NumRefs()
|
|
||||||
data = data[:n]
|
data = data[:n]
|
||||||
refs = refs[r.pc.refs:]
|
refs = refs[r.pc.refs:]
|
||||||
refs = refs[:nrefs]
|
refs = refs[:nrefs]
|
||||||
@@ -125,10 +125,10 @@ func (r *Reader) Decode() (EncodedOp, bool) {
|
|||||||
if deferring {
|
if deferring {
|
||||||
deferring = false
|
deferring = false
|
||||||
// Copy macro for deferred execution.
|
// Copy macro for deferred execution.
|
||||||
if t.NumRefs() != 1 {
|
if nrefs != 1 {
|
||||||
panic("internal error: unexpected number of macro refs")
|
panic("internal error: unexpected number of macro refs")
|
||||||
}
|
}
|
||||||
deferData := Write1(&r.deferOps, t.Size(), refs[0])
|
deferData := Write1(&r.deferOps, n, refs[0])
|
||||||
copy(deferData, data)
|
copy(deferData, data)
|
||||||
r.pc.data += n
|
r.pc.data += n
|
||||||
r.pc.refs += nrefs
|
r.pc.refs += nrefs
|
||||||
|
|||||||
Reference in New Issue
Block a user