pooltypes.go raw
1 // generated by go run github.com/p9c/gel/poolgen/poolgen.go; DO NOT EDIT
2 //
3 //go:generate go run ./poolgen/.
4
5 package gel
6
7 func (p *Pool) GetBool() (out *Bool) {
8 if len(p.bools) >= p.boolsInUse {
9 for i := 0; i < 10; i++ {
10 p.bools = append(p.bools, p.Bool(false))
11 }
12 }
13 out = p.bools[p.boolsInUse]
14 p.boolsInUse++
15 return
16 }
17
18 func (p *Pool) FreeBool(b *Bool) {
19 for i := 0; i < p.boolsInUse; i++ {
20 if p.bools[i] == b {
21 if i != p.boolsInUse-1 {
22 // move the item to the end. the next allocation will be then at index p.boolsInUse
23 tmp := p.bools[i]
24 p.bools = append(p.bools[:i], p.bools[i+1:]...)
25 p.bools = append(p.bools, tmp)
26 p.boolsInUse--
27 break
28 }
29 }
30 }
31 }
32
33
34 func (p *Pool) GetList() (out *List) {
35 if len(p.lists) >= p.listsInUse {
36 for i := 0; i < 10; i++ {
37 p.lists = append(p.lists, p.List())
38 }
39 }
40 out = p.lists[p.listsInUse]
41 p.listsInUse++
42 return
43 }
44
45 func (p *Pool) FreeList(b *List) {
46 for i := 0; i < p.listsInUse; i++ {
47 if p.lists[i] == b {
48 if i != p.listsInUse-1 {
49 // move the item to the end. the next allocation will be then at index p.listsInUse
50 tmp := p.lists[i]
51 p.lists = append(p.lists[:i], p.lists[i+1:]...)
52 p.lists = append(p.lists, tmp)
53 p.listsInUse--
54 break
55 }
56 }
57 }
58 }
59
60
61 func (p *Pool) GetCheckable() (out *Checkable) {
62 if len(p.checkables) >= p.checkablesInUse {
63 for i := 0; i < 10; i++ {
64 p.checkables = append(p.checkables, p.Checkable())
65 }
66 }
67 out = p.checkables[p.checkablesInUse]
68 p.checkablesInUse++
69 return
70 }
71
72 func (p *Pool) FreeCheckable(b *Checkable) {
73 for i := 0; i < p.checkablesInUse; i++ {
74 if p.checkables[i] == b {
75 if i != p.checkablesInUse-1 {
76 // move the item to the end. the next allocation will be then at index p.checkablesInUse
77 tmp := p.checkables[i]
78 p.checkables = append(p.checkables[:i], p.checkables[i+1:]...)
79 p.checkables = append(p.checkables, tmp)
80 p.checkablesInUse--
81 break
82 }
83 }
84 }
85 }
86
87
88 func (p *Pool) GetClickable() (out *Clickable) {
89 if len(p.clickables) >= p.clickablesInUse {
90 for i := 0; i < 10; i++ {
91 p.clickables = append(p.clickables, p.Clickable())
92 }
93 }
94 out = p.clickables[p.clickablesInUse]
95 p.clickablesInUse++
96 return
97 }
98
99 func (p *Pool) FreeClickable(b *Clickable) {
100 for i := 0; i < p.clickablesInUse; i++ {
101 if p.clickables[i] == b {
102 if i != p.clickablesInUse-1 {
103 // move the item to the end. the next allocation will be then at index p.clickablesInUse
104 tmp := p.clickables[i]
105 p.clickables = append(p.clickables[:i], p.clickables[i+1:]...)
106 p.clickables = append(p.clickables, tmp)
107 p.clickablesInUse--
108 break
109 }
110 }
111 }
112 }
113
114
115 func (p *Pool) GetEditor() (out *Editor) {
116 if len(p.editors) >= p.editorsInUse {
117 for i := 0; i < 10; i++ {
118 p.editors = append(p.editors, p.Editor())
119 }
120 }
121 out = p.editors[p.editorsInUse]
122 p.editorsInUse++
123 return
124 }
125
126 func (p *Pool) FreeEditor(b *Editor) {
127 for i := 0; i < p.editorsInUse; i++ {
128 if p.editors[i] == b {
129 if i != p.editorsInUse-1 {
130 // move the item to the end. the next allocation will be then at index p.editorsInUse
131 tmp := p.editors[i]
132 p.editors = append(p.editors[:i], p.editors[i+1:]...)
133 p.editors = append(p.editors, tmp)
134 p.editorsInUse--
135 break
136 }
137 }
138 }
139 }
140
141
142 func (p *Pool) GetIncDec() (out *IncDec) {
143 if len(p.incDecs) >= p.incDecsInUse {
144 for i := 0; i < 10; i++ {
145 p.incDecs = append(p.incDecs, p.IncDec())
146 }
147 }
148 out = p.incDecs[p.incDecsInUse]
149 p.incDecsInUse++
150 return
151 }
152
153 func (p *Pool) FreeIncDec(b *IncDec) {
154 for i := 0; i < p.incDecsInUse; i++ {
155 if p.incDecs[i] == b {
156 if i != p.incDecsInUse-1 {
157 // move the item to the end. the next allocation will be then at index p.incDecsInUse
158 tmp := p.incDecs[i]
159 p.incDecs = append(p.incDecs[:i], p.incDecs[i+1:]...)
160 p.incDecs = append(p.incDecs, tmp)
161 p.incDecsInUse--
162 break
163 }
164 }
165 }
166 }
167
168