mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
Bug 407483 - [performance] Performance improvements to decorators
On non-cdt projects, the decorators caused a ICProjectDescription to be created every time a resource was decorated. The decorators should only get the description when it already exists. Performance was also a bit improved on cdt projects by extracting some variables out of a loop. Change-Id: I125dc0ba55a72cfbd272fb6d6658474216021803 Reviewed-on: https://git.eclipse.org/r/12744 Reviewed-by: Andrew Gvozdev <angvoz.dev@gmail.com> IP-Clean: Andrew Gvozdev <angvoz.dev@gmail.com> Tested-by: Andrew Gvozdev <angvoz.dev@gmail.com>
This commit is contained in:
parent
f70ab948fc
commit
a1f59f3708
2 changed files with 14 additions and 7 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.viewsupport;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IFolder;
|
import org.eclipse.core.resources.IFolder;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -27,6 +28,7 @@ import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||||
|
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||||
|
@ -39,7 +41,8 @@ public class CustomBuildSettingsDecorator implements ILightweightLabelDecorator
|
||||||
public void decorate(Object element, IDecoration decoration) {
|
public void decorate(Object element, IDecoration decoration) {
|
||||||
if (element instanceof IFile || element instanceof IFolder) {
|
if (element instanceof IFile || element instanceof IFolder) {
|
||||||
IResource rc = (IResource) element;
|
IResource rc = (IResource) element;
|
||||||
ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(rc.getProject(), false);
|
ICProjectDescriptionManager projectDescriptionManager = CoreModel.getDefault().getProjectDescriptionManager();
|
||||||
|
ICProjectDescription prjDescription = projectDescriptionManager.getProjectDescription(rc.getProject(), ICProjectDescriptionManager.GET_IF_LOADDED);
|
||||||
if (prjDescription != null) {
|
if (prjDescription != null) {
|
||||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||||
if (cfgDescription != null) {
|
if (cfgDescription != null) {
|
||||||
|
@ -57,11 +60,13 @@ public class CustomBuildSettingsDecorator implements ILightweightLabelDecorator
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
|
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
|
||||||
|
IContainer parent = rc.getParent();
|
||||||
|
List<String> languages = LanguageSettingsManager.getLanguages(rc, cfgDescription);
|
||||||
for (ILanguageSettingsProvider provider: ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()) {
|
for (ILanguageSettingsProvider provider: ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders()) {
|
||||||
for (String languageId : LanguageSettingsManager.getLanguages(rc, cfgDescription)) {
|
for (String languageId : languages) {
|
||||||
List<ICLanguageSettingEntry> list = provider.getSettingEntries(cfgDescription, rc, languageId);
|
List<ICLanguageSettingEntry> list = provider.getSettingEntries(cfgDescription, rc, languageId);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
List<ICLanguageSettingEntry> listDefault = provider.getSettingEntries(cfgDescription, rc.getParent(), languageId);
|
List<ICLanguageSettingEntry> listDefault = provider.getSettingEntries(cfgDescription, parent, languageId);
|
||||||
// != is OK here due as the equal lists will have the same reference in WeakHashSet
|
// != is OK here due as the equal lists will have the same reference in WeakHashSet
|
||||||
if (list != listDefault)
|
if (list != listDefault)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2010 Atmel Corporation and others.
|
* Copyright (c) 2010, 2013 Atmel Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.ui.viewsupport;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IFolder;
|
import org.eclipse.core.resources.IFolder;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.jface.preference.JFacePreferences;
|
import org.eclipse.jface.preference.JFacePreferences;
|
||||||
import org.eclipse.jface.resource.JFaceResources;
|
import org.eclipse.jface.resource.JFaceResources;
|
||||||
import org.eclipse.jface.viewers.IDecoration;
|
import org.eclipse.jface.viewers.IDecoration;
|
||||||
|
@ -38,20 +39,21 @@ public class ExcludedFileDecorator implements ILightweightLabelDecorator {
|
||||||
if (element instanceof IFile || element instanceof IFolder) {
|
if (element instanceof IFile || element instanceof IFolder) {
|
||||||
IResource resource = (IResource) element;
|
IResource resource = (IResource) element;
|
||||||
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
|
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
|
||||||
ICProjectDescription desc = mngr.getProjectDescription(resource.getProject(), false);
|
ICProjectDescription desc = mngr.getProjectDescription(resource.getProject(), ICProjectDescriptionManager.GET_IF_LOADDED);
|
||||||
if (desc == null)
|
if (desc == null)
|
||||||
return;
|
return;
|
||||||
ICConfigurationDescription conf = desc.getDefaultSettingConfiguration();
|
ICConfigurationDescription conf = desc.getDefaultSettingConfiguration();
|
||||||
ICSourceEntry[] entries = conf.getSourceEntries();
|
ICSourceEntry[] entries = conf.getSourceEntries();
|
||||||
boolean isUnderSourceRoot = false;
|
boolean isUnderSourceRoot = false;
|
||||||
|
IPath fullPath = resource.getFullPath();
|
||||||
for (ICSourceEntry icSourceEntry : entries) {
|
for (ICSourceEntry icSourceEntry : entries) {
|
||||||
if (icSourceEntry.getFullPath().isPrefixOf(resource.getFullPath())) {
|
if (icSourceEntry.getFullPath().isPrefixOf(fullPath)) {
|
||||||
isUnderSourceRoot = true;
|
isUnderSourceRoot = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only bother to mark items that would be included otherwise
|
// Only bother to mark items that would be included otherwise
|
||||||
if (isUnderSourceRoot && CDataUtil.isExcluded(resource.getFullPath(), entries)) {
|
if (isUnderSourceRoot && CDataUtil.isExcluded(fullPath, entries)) {
|
||||||
decoration.addOverlay(CPluginImages.DESC_OVR_INACTIVE);
|
decoration.addOverlay(CPluginImages.DESC_OVR_INACTIVE);
|
||||||
decoration.setForegroundColor(JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR));
|
decoration.setForegroundColor(JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue