Skip to content

Commit 8d2c30f

Browse files
committed
Reduce freeze times on updating search results on resource changes
If the search view shows ~100000 matches, deleting resources that are shown in the search view freezes Eclipse for many minutes. With this change the freeze is only about 30 seconds. See #2279
1 parent 5af8f51 commit 8d2c30f

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

bundles/org.eclipse.search/newsearch/org/eclipse/search/ui/text/AbstractTextSearchResult.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.HashSet;
2222
import java.util.Iterator;
2323
import java.util.List;
24+
import java.util.Map.Entry;
2425
import java.util.Set;
2526
import java.util.concurrent.ConcurrentHashMap;
2627
import java.util.concurrent.ConcurrentMap;
@@ -308,6 +309,19 @@ public int getMatchCount() {
308309
return count;
309310
}
310311

312+
/**
313+
* @return {@code true} if the result is not empty
314+
* @since 3.17
315+
*/
316+
public boolean hasMatches() {
317+
for (Entry<Object, Set<Match>> entry : fElementsToMatches.entrySet()) {
318+
if (!entry.getValue().isEmpty()) {
319+
return true;
320+
}
321+
}
322+
return false;
323+
}
324+
311325
/**
312326
* Returns the number of matches reported against a given element. This is
313327
* equivalent to calling <code>getMatches(element).length</code>

bundles/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232

3333
import org.eclipse.core.resources.IProject;
3434
import org.eclipse.core.resources.IResource;
35+
3536
import org.eclipse.jface.viewers.AbstractTreeViewer;
3637
import org.eclipse.jface.viewers.ITreeContentProvider;
3738
import org.eclipse.jface.viewers.Viewer;
39+
3840
import org.eclipse.search.ui.text.AbstractTextSearchResult;
3941
import org.eclipse.search.ui.text.Match;
4042
import org.eclipse.search.ui.text.MatchFilter;
@@ -170,17 +172,27 @@ private boolean hasMatches(Object element) {
170172
if (element instanceof LineElement) {
171173
LineElement lineElement= (LineElement) element;
172174
IResource resource = lineElement.getParent();
173-
if (getMatchCount(resource) > 0) {
175+
if (hasMatches(resource)) {
174176
return lineElement.hasMatches(fResult);
175177
}
176178
}
177179
return fPage.getDisplayedMatchCount(element) > 0;
178180
}
179181

182+
private boolean hasMatches(IResource element) {
183+
if (hasActiveMatchFilters()) {
184+
return fPage.getDisplayedMatchCount(element) > 0;
185+
} else {
186+
return fResult.hasMatches();
187+
}
188+
}
189+
180190
private int getMatchCount(Object element) {
181-
return fResult.getActiveMatchFilters() != null && fResult.getActiveMatchFilters().length > 0
182-
? fPage.getDisplayedMatchCount(element)
183-
: fResult.getMatchCount();
191+
if (hasActiveMatchFilters()) {
192+
return fPage.getDisplayedMatchCount(element);
193+
} else {
194+
return fResult.getMatchCount();
195+
}
184196
}
185197

186198
private void removeFromSiblings(Object element, Object parent) {
@@ -208,7 +220,11 @@ public Object[] getChildren(Object parentElement) {
208220

209221
@Override
210222
public boolean hasChildren(Object element) {
211-
return getChildren(element).length > 0;
223+
Set<Object> children = fChildrenMap.get(element);
224+
if (children == null) {
225+
return false;
226+
}
227+
return !children.isEmpty();
212228
}
213229

214230
static <T> Stream<T> toStream(Enumeration<T> e) {
@@ -244,7 +260,7 @@ public synchronized void elementsChanged(Object[] updatedElements) {
244260
Set<LineElement> lineMatches = Collections.emptySet();
245261
// if we have active match filters, we should only use non-filtered FileMatch
246262
// objects to collect LineElements to update
247-
if (fResult.getActiveMatchFilters() != null && fResult.getActiveMatchFilters().length > 0) {
263+
if (hasActiveMatchFilters()) {
248264
lineMatches = Arrays.stream(updatedElements).filter(LineElement.class::isInstance)
249265
// only for distinct files:
250266
.map(u -> ((LineElement) u).getParent()).distinct()
@@ -293,6 +309,11 @@ public synchronized void elementsChanged(Object[] updatedElements) {
293309
}
294310
}
295311

312+
private boolean hasActiveMatchFilters() {
313+
MatchFilter[] activeMatchFilters = fResult.getActiveMatchFilters();
314+
return activeMatchFilters != null && activeMatchFilters.length > 0;
315+
}
316+
296317
@Override
297318
public void clear() {
298319
initialize(fResult);

0 commit comments

Comments
 (0)