Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Kubitz2021-09-09 18:41:47 -0400
committerJörg Kubitz2021-09-15 01:43:22 -0400
commit4d9292f2c3627512855770ef151e7ac369316b3f (patch)
tree05d85dab47f997c2f82b79ec86e331239d347cdd
parent1cb468e2e5862645e7d02d05c420118131018cfc (diff)
downloadeclipse.platform.text-4d9292f2c3627512855770ef151e7ac369316b3f.tar.gz
eclipse.platform.text-4d9292f2c3627512855770ef151e7ac369316b3f.tar.xz
eclipse.platform.text-4d9292f2c3627512855770ef151e7ac369316b3f.zip
Bug 575893 - [performance] improve Search result speedI20210915-0150
Avoid to query all Line Results of the file for every Line again. Now query every files Result only once. Change-Id: I1b73e4b4a9c00ff065ce86cfdc91b027569117ae Signed-off-by: Joerg Kubitz <jkubitz-eclipse@gmx.de> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/185270 Tested-by: Platform Bot <platform-bot@eclipse.org>
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java
index f0703db13..9b10aeda8 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java
@@ -16,10 +16,17 @@
*******************************************************************************/
package org.eclipse.search.internal.ui.text;
+import java.util.Arrays;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -192,9 +199,19 @@ public class FileTreeContentProvider implements ITreeContentProvider, IFileSearc
return getChildren(element).length > 0;
}
+ static <T> Stream<T> toStream(Enumeration<T> e) {
+ return StreamSupport.stream(Spliterators.spliteratorUnknownSize(e.asIterator(), Spliterator.ORDERED), false);
+ }
+
@Override
public synchronized void elementsChanged(Object[] updatedElements) {
boolean singleElement = updatedElements.length == 1;
+ Set<LineElement> lineMatches = Arrays.stream(updatedElements).filter(LineElement.class::isInstance)
+ // only for distinct files:
+ .map(u -> ((LineElement) u).getParent()).distinct()
+ // query matches:
+ .map(fResult::getMatchSet).flatMap(FileTreeContentProvider::toStream)
+ .map(m -> ((FileMatch) m).getLineElement()).collect(Collectors.toSet());
try {
for (Object updatedElement : updatedElements) {
if (!(updatedElement instanceof LineElement)) {
@@ -208,7 +225,7 @@ public class FileTreeContentProvider implements ITreeContentProvider, IFileSearc
// change events to line elements are reported in text
// search
LineElement lineElement = (LineElement) updatedElement;
- boolean hasMatches = lineElement.hasMatches(fResult);
+ boolean hasMatches = lineMatches.contains(lineElement);
if (hasMatches) {
if (singleElement && hasChild(lineElement.getParent(), lineElement)) {
fTreeViewer.update(new Object[] { lineElement, lineElement.getParent() }, null);

Back to the top