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

jpyinterpreter - make FOR_ITER use Java iterator loop format when possible #113

Open
Christopher-Chianelli opened this issue Oct 28, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@Christopher-Chianelli
Copy link
Contributor

Currently, in order to fully support all the forms a Python iterator can take, jpyinterpreter generates the following code for FOR_ITER:

try {
    do {
        TOS' = next(TOS)
         // code in for block
    } while(true);
} catch (StopIteration e) {
    // code after for block
}

This is highly atypical in Java, and the JVM probably would have a harder time optimizing its standard for iterator loop:

while (TOS.hasNext()) {
    TOS' = TOS.next();
    // code in for block
}
 // code after for block

We can look at TOS to see if it a known iterator type (i.e. PythonIterator), and if so, generate the more typical Java loop.

@Christopher-Chianelli Christopher-Chianelli added the enhancement New feature or request label Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant