timing.core: Make ArrayList use the array of segments if possible
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 18 May 2016 15:19:28 +0000 (11:19 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 30 May 2016 17:42:25 +0000 (13:42 -0400)
Bulk load arrays if possible to speed up the serialized segment store.

Change-Id: I55a389419b7fe3182ee3d0fae90c16d9c6bab5a2
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/73061
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/AbstractSegmentStoreAnalysisModule.java
analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/store/ArrayListStore.java

index 0518880fdc1344f4d76a86d72d7e28fb4e097bb8..597b547e451c491beda94367b7a93653e99912c6 100644 (file)
@@ -23,6 +23,7 @@ import java.util.List;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.ListenerList;
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.analysis.timing.core.store.ArrayListStore;
 import org.eclipse.tracecompass.segmentstore.core.ISegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
@@ -146,13 +147,7 @@ public abstract class AbstractSegmentStoreAnalysisModule extends TmfAbstractAnal
                 /* Attempt to read the existing file */
                 try (ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file))) {
                     Object[] segmentArray = readObject(ois);
-                    final ISegmentStore<ISegment> store = new ArrayListStore<>();
-                    for (Object element : segmentArray) {
-                        if (element instanceof ISegment) {
-                            ISegment segment = (ISegment) element;
-                            store.add(segment);
-                        }
-                    }
+                    ISegmentStore<ISegment> store = new ArrayListStore<>(NonNullUtils.checkNotNullContents(segmentArray));
                     fSegmentStore = store;
                     sendUpdate(store);
                     return true;
index 0e1f494b30a5f8b4970ccde5ea7696b34d05b61f..86c67351ed5b3d0a32cb62b737b9596be09de18d 100644 (file)
@@ -62,7 +62,7 @@ public class ArrayListStore<@NonNull E extends ISegment> implements ISegmentStor
 
     private final ReadWriteLock fLock = new ReentrantReadWriteLock(false);
 
-    private final List<E> fStore = new ArrayList<>();
+    private final List<E> fStore;
 
     private @Nullable transient Iterable<E> fLastSnapshot = null;
 
@@ -70,18 +70,25 @@ public class ArrayListStore<@NonNull E extends ISegment> implements ISegmentStor
      * Constructor
      */
     public ArrayListStore() {
-        /*
-         * For the start times index, the "key comparator" will compare the
-         * start times as longs directly. This is the primary comparator for its
-         * tree map.
-         *
-         * The secondary "value" comparator will check the end times first.
-         *
-         * The same is done for the end times index, but swapping the first two
-         * comparators instead.
-         */
+        fStore = new ArrayList<>();
     }
 
+    /**
+     * Constructor
+     *
+     * @param array
+     *            an array of elements to wrap in the segment store
+     *
+     */
+    public ArrayListStore(Object[] array) {
+        fStore = new ArrayList<>();
+        for (int i = 0; i < array.length; i++) {
+            if (array[i] instanceof ISegment) {
+                fStore.add((E) array[i]);
+            }
+        }
+        fStore.sort(COMPARATOR);
+    }
     // ------------------------------------------------------------------------
     // Methods from Collection
     // ------------------------------------------------------------------------
This page took 0.04364 seconds and 5 git commands to generate.