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

Implement the fast version of Stream#toList()? #26

Open
ZZZank opened this issue Jan 19, 2025 · 0 comments
Open

Implement the fast version of Stream#toList()? #26

ZZZank opened this issue Jan 19, 2025 · 0 comments

Comments

@ZZZank
Copy link

ZZZank commented Jan 19, 2025

The default implementation of Stream#toList() is already implemented by JVMDG:

// java default
    default List<T> toList() {
        return (List<T>) Collections.unmodifiableList(new ArrayList<>(Arrays.asList(this.toArray())));
    }

// jvmdg stub
    public static <T> List<T> toList(Stream<T> stream) {
        return Collections.unmodifiableList(new ArrayList(Arrays.asList(stream.toArray())));
    }

But there's a fast variant of Stream#toList() in java.util.stream.ReferencePipeline:

    @Override
    public List<P_OUT> toList() {
        return SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArrayNullsAllowed(this.toArray());
    }

// where the 'listFromTrustedArrayNullsAllowed' is
    static <E> List<E> listFromTrustedArrayNullsAllowed(Object... input) {
        assert input.getClass() == Object[].class;

        return input.length == 0 ? EMPTY_LIST_NULLS : new ListN(input, true);
    }

// the 'ListN' is in 'java.util.ImmutableCollections'

Is it possible to implement this in JVMDownGrader?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant