-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add Iterators and use them for for #3814
Conversation
2b8db6b
to
a4cf060
Compare
80a6e9d
to
011af15
Compare
|
||
int count=*p_args[0]; | ||
|
||
RangeIterator *itr = memnew(RangeIterator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure -- is this the right way to allocate? It works, that's great, but does it leak memory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It leaks, yes. I made it a Reference because I couldn't find any convenient location to call memdelete
. To fix it, replace the allocations with Refs:
Ref<RangeIterator> itr = Ref<RangeIterator>( memnew(RangeIterator) );
01596c9
to
7a08792
Compare
I like the One more thing -- the first RangeIterator had some naming convention mistakes and other issues that I meant to fix in a second commit. You might want to add it, but it does rename |
7a08792
to
e1b7beb
Compare
Thanks, the new commit is now added. I've squashed two commits, to keep the history clean. |
👍 |
Wow, this is awesome, please merge. |
e1b7beb
to
d2e1854
Compare
Also update classes.xml in order to document xrange
Make the parser eliminate a wasteful allocation and initialisation of a possibly large array.
d2e1854
to
5f66692
Compare
Add Iterators and use them for for
Please revert this, let me review it properly first |
Also please don't merge anything related to GDScript without me reviewing it first |
Revert "Merge pull request #3814 from est31/iterators_for_for"
Reverted by #3894. |
@vnen the code does not look bad, I agree, but it turns out to be slower, by a large factor. That's why it was reverted. |
The overhead of calling an Object's The only way this iterator could be as fast as an Array is if we modify the |
@sheepandshepherd Calling the function directly would essentially break custom iterators built in GDScript. |
Fixes #3765 . I believe this is a great addition and speedup for GDscript.
The PR does three things, in three commits:
RangeIterator
class. Many thanks to @sheepandshepherd for writing the class!xrange
function similar to the one in Python 2, and document the functionrange
withxrange
for for loops. This is guaranteed to be 100% backwards compatible, unless you relied onfor i in range(...)
to allocate memory xD... I'm not really proud of how I hacked the parser to do it but this is most conservative regarding backwards compatibility. Note that theGDParser::_reduce_expression
method does stuff like this as well, so I guess its fine. It catches 99% of all uses. Or do you know somebody who assigns range to a variable and then loops over the variable?