-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: split next into nextval & nextstate #9182
Conversation
Why not call it |
This is a cool approach. FWIW, I think using a Nullable would be a little simpler. |
@johnmyleswhite Do you mean something like this: function nextmaybe(a::AbstractArray, i)
i > length(a) ? Nullable() : Nullable(a[i]), i+1
end
iter = start(xs)
while true
maybe,iter = nextmaybe(xs,iter)
maybe.isnull && break
x = maybe.value
...
end i.e., #8149 (comment)? This PR basically implements C++-style iterators, while the above is more Python-like ( I guess i feel this PR is a little simpler:
@eschnett Sure, |
There's some evidence in #9080 that---at least on some architectures---a version of this PR might enable higher performance. It would appear to mandate putting |
For example, for x in xs ... now transforms into iter = start(xs) while !done(xs,iter) x = nextval(xs,iter) ... iter = nextstate(xs,iter)
Ok, i've moved |
Cool! I'll have to test this on #9080, but I gotta run for now. |
Sorry for the long delay. This indeed helps #9080 a bit:
It doesn't eliminate the gap, but it is a 10% speed improvement, or equivalently erases 25% of the gap. I was also hoping it would help the performance of On balance I like this change; I suppose the question is whether it is worth the breakage. |
For what it's worth, I'm still interested in doing this. I guess the open issues would be how to do it without breaking everything. Might be a good change for the Arraymageddon. |
Yes, something is not quite right about iteration yet. I think the most common awkward situation is that you don't know whether you're done until you try to fetch the next value, which doesn't fit cleanly into our current iteration model. |
Cross reference: #8149 |
This is a more speculative and breaking fix for #9178. It splits
next
intonextval
andnextstate
, as previously discussed in #6125.For example,
would transform into