datastore: Rewrite some stream and list manipulations
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 23 Feb 2017 22:07:47 +0000 (17:07 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Thu, 2 Mar 2017 20:03:47 +0000 (15:03 -0500)
This patch rewrites some list and stream manipulations to plain
java. It has a non-negligeable impact on performance.

Change-Id: I11881780d30f27592765140edda1af04b1a2c1e5
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/91757
Reviewed-by: Hudson CI
Reviewed-by: Loic Prieur-Drevon <loic.prieur.drevon@ericsson.com>
statesystem/org.eclipse.tracecompass.datastore.core/src/org/eclipse/tracecompass/internal/provisional/datastore/core/historytree/AbstractHistoryTree.java
statesystem/org.eclipse.tracecompass.datastore.core/src/org/eclipse/tracecompass/internal/provisional/datastore/core/historytree/HTNode.java

index b61152059ec06a16168d07ecaf17ac430c6a0da5..b606d55a5dbc1a1f1000fea40d78896730076177 100644 (file)
@@ -38,7 +38,6 @@ import org.eclipse.tracecompass.internal.provisional.datastore.core.interval.IHT
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
 
 /**
  * Base class for history trees that encapsulates the logic to read from/write
@@ -888,7 +887,7 @@ public abstract class AbstractHistoryTree<E extends IHTInterval, N extends HTNod
 
         // TODO Change this to evaluate the nodes lazily
 
-        List<Iterable<E>> intervalsOfNodes = new LinkedList<>();
+        List<E> intervalsOfNodes = new ArrayList<>();
 
         /* Queue is a stack of nodes containing nodes intersecting t */
         Deque<Integer> queue = new LinkedList<>();
@@ -911,12 +910,12 @@ public abstract class AbstractHistoryTree<E extends IHTInterval, N extends HTNod
                     /* Here we add the relevant children nodes for BFS */
                     queue.addAll(currentNode.selectNextChildren(nodeCondition));
                 }
-                Iterable<E> nodeIntervals = currentNode.getMatchingIntervals(nodeCondition, extraPredicate);
-                intervalsOfNodes.add(nodeIntervals);
+                Collection<E> nodeIntervals = currentNode.getMatchingIntervals(nodeCondition, extraPredicate);
+                intervalsOfNodes.addAll(nodeIntervals);
             }
         } catch (ClosedChannelException e) {
         }
-        return Iterables.concat(intervalsOfNodes);
+        return intervalsOfNodes;
     }
 
     @Override
index 3c3794b489d63150d2b35b1a1dc21cd79765637a..7a29d64a22f2f752fba12ef3db812dddaaeb9417 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.function.Predicate;
-import java.util.stream.Collectors;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
@@ -312,9 +311,11 @@ public class HTNode<E extends IHTInterval> implements IHTNode<E> {
         public final Collection<Integer> selectNextChildren(TimeRangeCondition timeCondition) {
             fNode.takeReadLock();
             try {
-                return selectNextIndices(timeCondition).stream()
-                        .map(i -> fChildren[i])
-                        .collect(Collectors.toList());
+                List<Integer> list = new ArrayList<>();
+                for (int index : selectNextIndices(timeCondition)) {
+                    list.add(fChildren[index]);
+                }
+                return list;
             } finally {
                 fNode.releaseReadLock();
             }
@@ -688,11 +689,10 @@ public class HTNode<E extends IHTInterval> implements IHTNode<E> {
     }
 
     @Override
-    public Iterable<E> getMatchingIntervals(TimeRangeCondition timeCondition,
+    public Collection<E> getMatchingIntervals(TimeRangeCondition timeCondition,
             Predicate<E> extraPredicate) {
 
         // TODO Benchmark using/returning streams instead of iterables
-
         if (isOnDisk()) {
             return doGetMatchingIntervals(timeCondition, extraPredicate);
         }
@@ -721,7 +721,7 @@ public class HTNode<E extends IHTInterval> implements IHTNode<E> {
         }
     }
 
-    private Iterable<E> doGetMatchingIntervals(TimeRangeCondition timeCondition,
+    private Collection<E> doGetMatchingIntervals(TimeRangeCondition timeCondition,
             Predicate<E> extraPredicate) {
         List<E> list = new ArrayList<>();
         for (int i = getStartIndexFor(timeCondition, extraPredicate); i < fIntervals.size(); i++) {
This page took 0.027719 seconds and 5 git commands to generate.