~eliasnaur/gio-patches

gio: layout: skip zero value Inset v1 PROPOSED

~pierrec
~pierrec: 1
 layout: skip zero value Inset

 2 files changed, 21 insertions(+), 0 deletions(-)
#509522 apple.yml success
#509523 freebsd.yml success
#509524 linux.yml success
#509525 openbsd.yml success
Le mer. 19 mai 2021 à 16:16, Elias Naur <mail@eliasnaur.com> a écrit :
Next
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/22819/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gio] layout: skip zero value Inset Export this patch

~pierrec
From: pierre <pierre.curto@gmail.com>

name                old time/op  new time/op  delta
Inset_LayoutZero-8  90.4ns ± 5%  14.3ns ± 3%  -84.22%  (p=0.000 n=9+10)
Inset_Layout-8       102ns ± 4%   111ns ±17%   +8.98%  (p=0.000 n=10+9)
Signed-off-by: pierre <pierre.curto@gmail.com>
---
-

 layout/layout.go      |  3 +++
 layout/layout_test.go | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/layout/layout.go b/layout/layout.go
index a13572e..89080ea 100644
--- a/layout/layout.go
+++ b/layout/layout.go
@@ -118,6 +118,9 @@ type Inset struct {

// Layout a widget.
func (in Inset) Layout(gtx Context, w Widget) Dimensions {
	if in == (Inset{}) {
		return w(gtx)
	}
	top := gtx.Px(in.Top)
	right := gtx.Px(in.Right)
	bottom := gtx.Px(in.Bottom)
diff --git a/layout/layout_test.go b/layout/layout_test.go
index f46fbfc..3d58520 100644
--- a/layout/layout_test.go
+++ b/layout/layout_test.go
@@ -7,6 +7,7 @@ import (
	"testing"

	"gioui.org/op"
	"gioui.org/unit"
)

func TestStack(t *testing.T) {
@@ -29,3 +30,20 @@ func TestStack(t *testing.T) {
		t.Errorf("Stack ignored Expanded size, got %v expected %v", got, exp)
	}
}

func BenchmarkInset_LayoutZero(b *testing.B) {
	benchmarkInset_Layout(b, Inset{})
}

func BenchmarkInset_Layout(b *testing.B) {
	benchmarkInset_Layout(b, UniformInset(unit.Dp(4)))
}

func benchmarkInset_Layout(b *testing.B, in Inset) {
	gtx := Context{Ops: new(op.Ops)}
	for i := 0; i < b.N; i++ {
		in.Layout(gtx, func(gtx Context) Dimensions {
			return Dimensions{}
		})
	}
}
-- 
2.30.2
builds.sr.ht
gio/patches: SUCCESS in 23m19s

[layout: skip zero value Inset][0] from [~pierrec][1]

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

✓ #509522 SUCCESS gio/patches/apple.yml   https://builds.sr.ht/~eliasnaur/job/509522
✓ #509523 SUCCESS gio/patches/freebsd.yml https://builds.sr.ht/~eliasnaur/job/509523
✓ #509524 SUCCESS gio/patches/linux.yml   https://builds.sr.ht/~eliasnaur/job/509524
✓ #509525 SUCCESS gio/patches/openbsd.yml https://builds.sr.ht/~eliasnaur/job/509525