~eliasnaur/gio

gio/layout/alloc_test.go -rw-r--r-- 831 bytes
918a5da3Egon Elbre Many operations do not pass refs to Write. Similarly adding 5 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: Unlicense OR MIT

// +build !race

package layout

import (
	"image"
	"testing"

	"gioui.org/op"
)

func TestStackAllocs(t *testing.T) {
	var ops op.Ops
	allocs := testing.AllocsPerRun(1, func() {
		ops.Reset()
		gtx := Context{
			Ops: &ops,
		}
		Stack{}.Layout(gtx,
			Stacked(func(gtx Context) Dimensions {
				return Dimensions{Size: image.Point{X: 50, Y: 50}}
			}),
		)
	})
	if allocs != 0 {
		t.Errorf("expected no allocs, got %f", allocs)
	}
}

func TestFlexAllocs(t *testing.T) {
	var ops op.Ops
	allocs := testing.AllocsPerRun(1, func() {
		ops.Reset()
		gtx := Context{
			Ops: &ops,
		}
		Flex{}.Layout(gtx,
			Rigid(func(gtx Context) Dimensions {
				return Dimensions{Size: image.Point{X: 50, Y: 50}}
			}),
		)
	})
	if allocs != 0 {
		t.Errorf("expected no allocs, got %f", allocs)
	}
}