~eliasnaur/gio-patches

gio: internal/ops: avoid bounds check in OpType.Size() v1 PROPOSED

~egonelbre: 1
 internal/ops: avoid bounds check in OpType.Size()

 1 files changed, 43 insertions(+), 41 deletions(-)
#792725 apple.yml success
#792726 freebsd.yml success
#792727 linux.yml success
#792728 openbsd.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/33494/mbox | git am -3
Learn more about email & git

[PATCH gio] internal/ops: avoid bounds check in OpType.Size() Export this patch

From: Egon Elbre <egonelbre@gmail.com>

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
---
 internal/ops/ops.go | 84 +++++++++++++++++++++++----------------------
 1 file changed, 43 insertions(+), 41 deletions(-)

diff --git a/internal/ops/ops.go b/internal/ops/ops.go
index 275a15ad..2d4d1138 100644
--- a/internal/ops/ops.go
+++ b/internal/ops/ops.go
@@ -380,48 +380,50 @@ func DecodeLoad(data []byte) int {
	return int(bo.Uint32(data[1:]))
}

var opSize = [0x100]byte{
	TypeMacro:            TypeMacroLen,
	TypeCall:             TypeCallLen,
	TypeDefer:            TypeDeferLen,
	TypePushTransform:    TypePushTransformLen,
	TypeTransform:        TypeTransformLen,
	TypePopTransform:     TypePopTransformLen,
	TypeInvalidate:       TypeRedrawLen,
	TypeImage:            TypeImageLen,
	TypePaint:            TypePaintLen,
	TypeColor:            TypeColorLen,
	TypeLinearGradient:   TypeLinearGradientLen,
	TypePass:             TypePassLen,
	TypePopPass:          TypePopPassLen,
	TypePointerInput:     TypePointerInputLen,
	TypeClipboardRead:    TypeClipboardReadLen,
	TypeClipboardWrite:   TypeClipboardWriteLen,
	TypeSource:           TypeSourceLen,
	TypeTarget:           TypeTargetLen,
	TypeOffer:            TypeOfferLen,
	TypeKeyInput:         TypeKeyInputLen,
	TypeKeyFocus:         TypeKeyFocusLen,
	TypeKeySoftKeyboard:  TypeKeySoftKeyboardLen,
	TypeSave:             TypeSaveLen,
	TypeLoad:             TypeLoadLen,
	TypeAux:              TypeAuxLen,
	TypeClip:             TypeClipLen,
	TypePopClip:          TypePopClipLen,
	TypeProfile:          TypeProfileLen,
	TypeCursor:           TypeCursorLen,
	TypePath:             TypePathLen,
	TypeStroke:           TypeStrokeLen,
	TypeSemanticLabel:    TypeSemanticLabelLen,
	TypeSemanticDesc:     TypeSemanticDescLen,
	TypeSemanticClass:    TypeSemanticClassLen,
	TypeSemanticSelected: TypeSemanticSelectedLen,
	TypeSemanticDisabled: TypeSemanticDisabledLen,
	TypeSnippet:          TypeSnippetLen,
	TypeSelection:        TypeSelectionLen,
	TypeActionInput:      TypeActionInputLen,
}

func (t OpType) Size() int {
	return [...]int{
		TypeMacroLen,
		TypeCallLen,
		TypeDeferLen,
		TypePushTransformLen,
		TypeTransformLen,
		TypePopTransformLen,
		TypeRedrawLen,
		TypeImageLen,
		TypePaintLen,
		TypeColorLen,
		TypeLinearGradientLen,
		TypePassLen,
		TypePopPassLen,
		TypePointerInputLen,
		TypeClipboardReadLen,
		TypeClipboardWriteLen,
		TypeSourceLen,
		TypeTargetLen,
		TypeOfferLen,
		TypeKeyInputLen,
		TypeKeyFocusLen,
		TypeKeySoftKeyboardLen,
		TypeSaveLen,
		TypeLoadLen,
		TypeAuxLen,
		TypeClipLen,
		TypePopClipLen,
		TypeProfileLen,
		TypeCursorLen,
		TypePathLen,
		TypeStrokeLen,
		TypeSemanticLabelLen,
		TypeSemanticDescLen,
		TypeSemanticClassLen,
		TypeSemanticSelectedLen,
		TypeSemanticDisabledLen,
		TypeSnippetLen,
		TypeSelectionLen,
		TypeActionInputLen,
	}[t-firstOpIndex]
	return int(opSize[t])
}

func (t OpType) NumRefs() int {
-- 
2.34.2
gio/patches: SUCCESS in 21m45s

[internal/ops: avoid bounds check in OpType.Size()][0] from [~egonelbre][1]

[0]: https://lists.sr.ht/~eliasnaur/gio-patches/patches/33494
[1]: mailto:egonelbre@gmail.com

✓ #792726 SUCCESS gio/patches/freebsd.yml https://builds.sr.ht/~eliasnaur/job/792726
✓ #792728 SUCCESS gio/patches/openbsd.yml https://builds.sr.ht/~eliasnaur/job/792728
✓ #792725 SUCCESS gio/patches/apple.yml   https://builds.sr.ht/~eliasnaur/job/792725
✓ #792727 SUCCESS gio/patches/linux.yml   https://builds.sr.ht/~eliasnaur/job/792727
Thanks, merged.

Elias