Skip to content

Commit

Permalink
Improve performance of Streams#stream
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSchumacher committed May 28, 2018
1 parent d9b6d37 commit 3aeaf37
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/org/assertj/core/util/Streams.java
Expand Up @@ -12,13 +12,19 @@
*/ */
package org.assertj.core.util; package org.assertj.core.util;


import java.util.Collection;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;


public class Streams { public class Streams {


public static <T> Stream<T> stream(Iterable<T> actual) { /**
return StreamSupport.stream(actual.spliterator(), false); * Returns a sequential {@link Stream} of the contents of {@code iterable}, delegating to {@link

* Collection#stream} if possible.
*/
public static <T> Stream<T> stream(Iterable<T> iterable) {
return (iterable instanceof Collection)
? ((Collection<T>) iterable).stream()
: StreamSupport.stream(iterable.spliterator(), false);
} }
} }

0 comments on commit 3aeaf37

Please sign in to comment.