Skip to content

Commit

Permalink
Added usage of cachedScalar for size()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Hinkes committed Jun 5, 2017
1 parent f1e99df commit a5e3958
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/org/cactoos/list/IterableAsList.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import org.cactoos.func.CachedScalar;
import org.cactoos.func.UncheckedScalar;
import org.cactoos.text.FormattedText;

/**
Expand All @@ -52,12 +54,8 @@ public final class IterableAsList<T> extends AbstractList<T> {

/**
* Iterable length.
*
* @todo #39:30m Needs cached `LengthOfIterable` version
* to improve `IterableAsList` performance. Now each call
* to `size()` goes through all iterable to calculate the size.
*/
private final LengthOfIterable length;
private final UncheckedScalar<Integer> length;

/**
* Ctor.
Expand All @@ -68,7 +66,11 @@ public IterableAsList(final Iterable<T> iterable) {
super();
this.source = iterable;
this.cache = new ArrayList<>(0);
this.length = new LengthOfIterable(iterable);
this.length = new UncheckedScalar<>(
new CachedScalar<>(
new LengthOfIterable(iterable)
)
);
}

@Override
Expand Down

0 comments on commit a5e3958

Please sign in to comment.