use multipointers instead of simple pointers

This commit is contained in:
Andrea Piseri
2021-12-28 16:22:34 +01:00
parent 822da9d12d
commit 92e70b9a58
+6 -10
View File
@@ -306,21 +306,17 @@ filter :: proc(s: $S/[]$U, f: proc(U) -> bool, allocator := context.allocator) -
scanner :: proc (s: $S/[]$U, initializer: $V, f: proc(V, U)->V, allocator := context.allocator) -> []V { scanner :: proc (s: $S/[]$U, initializer: $V, f: proc(V, U)->V, allocator := context.allocator) -> []V {
if len(s) == 0 { return {} } if len(s) == 0 { return {} }
p := as_ptr(s)
res := make([]V, len(s), allocator) res := make([]V, len(s), allocator)
p := as_ptr(s)
q := as_ptr(res) q := as_ptr(res)
l := len(res)
r := initializer r := initializer
for l > 0 { for l := len(s); l > 0; l -= 1 {
r = f(r, p^) r = f(r, p[0])
q^ = r q[0] = r
p = intrinsics.ptr_offset(p, 1) p = p[1:]
q = intrinsics.ptr_offset(q, 1) q = q[1:]
l -= 1
} }
return res return res