Skip to content

Commit 34fd70a

Browse files
authored
std: fix iterator dropping in List eq (#244)
1 parent 70469a4 commit 34fd70a

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

tests/programs/string_ops.vi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ pub fn main(&io: &IO) {
2323
io.println("{"hello" != "world"}");
2424
io.println("{"hello" == "hello world"}");
2525
io.println("{"world" == "hello world"}");
26+
27+
let x = "hi";
28+
io.println("{x == "xy"}");
29+
io.println("{x == "hi"}");
30+
io.println("{x}");
2631
}

tests/snaps/vine/string_ops/output.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ false
1313
true
1414
false
1515
false
16+
false
17+
true
18+
hi

tests/snaps/vine/string_ops/stats.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11

22
Interactions
3-
Total 3_397
4-
Depth 344
5-
Breadth 9
6-
Annihilate 1_517
3+
Total 3_866
4+
Depth 358
5+
Breadth 10
6+
Annihilate 1_752
77
Commute 0
8-
Copy 471
9-
Erase 522
10-
Expand 296
11-
Call 399
12-
Branch 192
8+
Copy 516
9+
Erase 580
10+
Expand 339
11+
Call 459
12+
Branch 220
1313

1414
Memory
15-
Heap 13_504 B
16-
Allocated 66_224 B
17-
Freed 66_224 B
15+
Heap 15_504 B
16+
Allocated 75_936 B
17+
Freed 75_936 B

vine/std/data/List.vi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,12 @@ pub mod List {
206206
if a.len() != b.len() {
207207
return false;
208208
}
209-
let a = a.iter();
210-
let b = b.iter();
211-
while a.next() is Some(&a) && b.next() is Some(&b) {
212-
if a != b {
209+
let a_iter = a.iter();
210+
let b_iter = b.iter();
211+
while a_iter.next() is Some(&a_elem) && b_iter.next() is Some(&b_elem) {
212+
if a_elem != b_elem {
213+
a_iter.drop();
214+
b_iter.drop();
213215
return false;
214216
}
215217
}

0 commit comments

Comments
 (0)