Author: schor Date: Fri May 6 20:34:28 2016 New Revision: 1742617 URL: http://svn.apache.org/viewvc?rev=1742617&view=rev Log: [UIMA-4664] convert cache from arraylist to array.
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java?rev=1742617&r1=1742616&r2=1742617&view=diff ============================================================================== --- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java (original) +++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java Fri May 6 20:34:28 2016 @@ -47,15 +47,25 @@ public abstract class FsIterator_subtype // subsequently ignored - same effect private FsIterator_singletype<T>[] initIterators() { iicp.createIndexIteratorCache(); - final ArrayList<FsIndex_singletype<FeatureStructure>> cachedSubIndexes = iicp.cachedSubFsLeafIndexes; + final FsIndex_singletype<FeatureStructure>[] cachedSubIndexes = iicp.cachedSubFsLeafIndexes; - FsIterator_singletype<T>[] r = cachedSubIndexes.stream() - .filter(leafIndex -> leafIndex.size() > 0) // filter out empty ones - .map( index -> index.iterator()) // map fsIndex_singletype to an iterator over that - .toArray(FsIterator_singletype[]::new); +// FsIterator_singletype<T>[] r = cachedSubIndexes.stream() +// .filter(leafIndex -> leafIndex.size() > 0) // filter out empty ones +// .map( index -> index.iterator()) // map fsIndex_singletype to an iterator over that +// .toArray(FsIterator_singletype[]::new); + ArrayList<FsIterator_singletype<T>> r = new ArrayList<>(); + for (FsIndex_singletype<FeatureStructure> leafIndex : iicp.cachedSubFsLeafIndexes) { + if (leafIndex.size() == 0) { + continue; + } + r.add((FsIterator_singletype<T>) leafIndex.iterator()); + } + // if all are empty, put the first one in (to avoid handling 0 as a special case) - return (r.length != 0) ? r : new FsIterator_singletype[] {(FsIterator_singletype) cachedSubIndexes.get(0).iterator()}; + return (r.size() != 0) + ? r.toArray(new FsIterator_singletype[r.size()]) + : new FsIterator_singletype[] {(FsIterator_singletype<T>) cachedSubIndexes[0].iterator()}; } /* (non-Javadoc) @@ -63,7 +73,11 @@ public abstract class FsIterator_subtype */ @Override public int ll_indexSize() { - return Arrays.stream(iterators).mapToInt(it -> it.ll_getIndex().size()).sum(); + int sz = 0; + for (FsIterator_singletype<T> it : iterators) { + sz += it.ll_getIndex().size(); + } + return sz; } }