mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 398611. Avoid calling IResource.findMarkers multiple times for the
same resource.
This commit is contained in:
parent
7be456a5de
commit
1cfda1b6e4
1 changed files with 51 additions and 12 deletions
|
@ -7,9 +7,13 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IResourceStatus;
|
import org.eclipse.core.resources.IResourceStatus;
|
||||||
|
@ -81,14 +85,43 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class MarkersCacheKey {
|
||||||
|
private IResource res;
|
||||||
|
private int depth;
|
||||||
|
|
||||||
|
public MarkersCacheKey(IResource res, int depth) {
|
||||||
|
this.res = res;
|
||||||
|
this.depth = depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return res.hashCode() + 31 * depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
MarkersCacheKey other = (MarkersCacheKey) obj;
|
||||||
|
return depth == other.depth && res.equals(other.res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final int ERRORTICK_WARNING= CElementImageDescriptor.WARNING;
|
private static final int ERRORTICK_WARNING= CElementImageDescriptor.WARNING;
|
||||||
private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR;
|
private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR;
|
||||||
|
private static final IMarker[] EMPTY_MARKER_ARRAY = {};
|
||||||
|
|
||||||
private ImageDescriptorRegistry fRegistry;
|
private ImageDescriptorRegistry fRegistry;
|
||||||
private boolean fUseNewRegistry;
|
private boolean fUseNewRegistry;
|
||||||
private IProblemChangedListener fProblemChangedListener;
|
private IProblemChangedListener fProblemChangedListener;
|
||||||
|
|
||||||
private ListenerList fListeners;
|
private ListenerList fListeners;
|
||||||
|
private Map<MarkersCacheKey, IMarker[]> fMarkersCache = new HashMap<MarkersCacheKey, IMarker[]>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <code>ProblemsLabelDecorator</code>.
|
* Creates a new <code>ProblemsLabelDecorator</code>.
|
||||||
|
@ -179,17 +212,22 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
}
|
}
|
||||||
int info= 0;
|
int info= 0;
|
||||||
|
|
||||||
IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth);
|
MarkersCacheKey cacheKey = new MarkersCacheKey(res, depth);
|
||||||
if (markers != null) {
|
IMarker[] markers = fMarkersCache .get(cacheKey);
|
||||||
for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) {
|
if (markers == null) {
|
||||||
IMarker curr= markers[i];
|
markers= res.findMarkers(IMarker.PROBLEM, true, depth);
|
||||||
if (sourceElement == null || isMarkerInRange(curr, sourceElement)) {
|
if (markers == null)
|
||||||
int priority= curr.getAttribute(IMarker.SEVERITY, -1);
|
markers = EMPTY_MARKER_ARRAY;
|
||||||
if (priority == IMarker.SEVERITY_WARNING) {
|
fMarkersCache.put(cacheKey, markers);
|
||||||
info= ERRORTICK_WARNING;
|
}
|
||||||
} else if (priority == IMarker.SEVERITY_ERROR) {
|
for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) {
|
||||||
info= ERRORTICK_ERROR;
|
IMarker curr= markers[i];
|
||||||
}
|
if (sourceElement == null || isMarkerInRange(curr, sourceElement)) {
|
||||||
|
int priority= curr.getAttribute(IMarker.SEVERITY, -1);
|
||||||
|
if (priority == IMarker.SEVERITY_WARNING) {
|
||||||
|
info= ERRORTICK_WARNING;
|
||||||
|
} else if (priority == IMarker.SEVERITY_ERROR) {
|
||||||
|
info= ERRORTICK_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +264,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
protected boolean isInside(int offSet, int line, ISourceReference sourceElement) throws CoreException {
|
protected boolean isInside(int offSet, int line, ISourceReference sourceElement) throws CoreException {
|
||||||
ISourceRange range= sourceElement.getSourceRange();
|
ISourceRange range= sourceElement.getSourceRange();
|
||||||
if (range != null) {
|
if (range != null) {
|
||||||
if (offSet ==-1) {
|
if (offSet == -1) {
|
||||||
return (line >= range.getStartLine() && line <= range.getEndLine());
|
return (line >= range.getStartLine() && line <= range.getEndLine());
|
||||||
}
|
}
|
||||||
int rangeOffset= range.getStartPos();
|
int rangeOffset= range.getStartPos();
|
||||||
|
@ -280,6 +318,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fireProblemsChanged(IResource[] changedResources, boolean isMarkerChange) {
|
protected void fireProblemsChanged(IResource[] changedResources, boolean isMarkerChange) {
|
||||||
|
fMarkersCache.clear();
|
||||||
if (fListeners != null && !fListeners.isEmpty()) {
|
if (fListeners != null && !fListeners.isEmpty()) {
|
||||||
LabelProviderChangedEvent event= new ProblemsLabelChangedEvent(this, changedResources, isMarkerChange);
|
LabelProviderChangedEvent event= new ProblemsLabelChangedEvent(this, changedResources, isMarkerChange);
|
||||||
Object[] listeners= fListeners.getListeners();
|
Object[] listeners= fListeners.getListeners();
|
||||||
|
|
Loading…
Add table
Reference in a new issue