Skip to content
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

Java Iterables #45

Closed
nournia opened this issue Nov 26, 2012 · 1 comment
Closed

Java Iterables #45

nournia opened this issue Nov 26, 2012 · 1 comment

Comments

@nournia
Copy link

nournia commented Nov 26, 2012

Programming in python based on lists and other collections. I think it's better to convert them instantly. I mean you should reduce switching between python and JVM. Take a look at this example:

while iterator.hasNext():
    print iterator.next()

That needs switching to JVM for each item. But there isn't any need if you convert Java Iterable to python list. Or this one with same performance issue:

for i in range(arr.length):
    print list[i]
@tito
Copy link
Member

tito commented Dec 4, 2012

I don't agreed. The whole goal of iterator is to prevent to not duplicate the list memory, and instead, get the item one by one. If we add magic to use python list, the memory used would be at mimimun x2.

However, if you have the choice of using a list (if the initial object has a toList(), toArray(), or something like that), then use it!

@tito tito closed this as completed Dec 4, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants