Skip to content

Commit 7e9f44f

Browse files
authored
Merge pull request #16 from spytheman/reduce_leaks
reduce some leaks, render at most 1 update per frame (it makes showcase.v responsive on linux for a slower i3 CPU)
2 parents 8947463 + 77785cf commit 7e9f44f

10 files changed

Lines changed: 5397 additions & 5331 deletions

File tree

animation.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn (mut w Window) animation_add(mut animation Animation) {
3030
w.animations << animation
3131
}
3232

33-
fn (mut w Window) animaton_loop() {
33+
fn (mut w Window) animation_loop() {
3434
for {
3535
time.sleep(animation_cycle)
3636
w.lock()

event_handlers.v

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ fn mouse_down_handler(node &Layout, in_handler bool, mut e Event, mut w Window)
102102
return
103103
}
104104
}
105-
for child in node.children.reverse() {
105+
for i := node.children.len - 1; node.children.len > 0 && i >= 0; i-- {
106+
child := unsafe { &node.children[i] }
106107
mouse_down_handler(child, true, mut e, mut w)
107108
if e.is_handled {
108109
return
@@ -141,7 +142,8 @@ fn mouse_move_handler(node &Layout, mut e Event, mut w Window) {
141142
if !w.pointer_over_app(e) {
142143
return
143144
}
144-
for child in node.children.reverse() {
145+
for i := node.children.len - 1; node.children.len > 0 && i >= 0; i-- {
146+
child := unsafe { &node.children[i] }
145147
mouse_move_handler(child, mut e, mut w)
146148
if e.is_handled {
147149
return
@@ -165,7 +167,8 @@ fn mouse_up_handler(node &Layout, mut e Event, mut w Window) {
165167
w.view_state.mouse_lock.mouse_up(node, mut e, mut w)
166168
return
167169
}
168-
for child in node.children.reverse() {
170+
for i := node.children.len - 1; node.children.len > 0 && i >= 0; i-- {
171+
child := unsafe { &node.children[i] }
169172
mouse_up_handler(child, mut e, mut w)
170173
if e.is_handled {
171174
return
@@ -197,7 +200,8 @@ fn mouse_up_handler(node &Layout, mut e Event, mut w Window) {
197200
}
198201

199202
fn mouse_scroll_handler(node &Layout, mut e Event, mut w Window) {
200-
for child in node.children.reverse() {
203+
for i := node.children.len - 1; node.children.len > 0 && i >= 0; i-- {
204+
child := unsafe { &node.children[i] }
201205
mouse_scroll_handler(child, mut e, mut w)
202206
if e.is_handled {
203207
return

0 commit comments

Comments
 (0)