1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Use WeakHashMap to keep LSE lists in common pool.

This commit is contained in:
Andrew Gvozdev 2011-07-23 08:13:57 -04:00
parent 728e669707
commit 2d2311a2a6

View file

@ -26,6 +26,7 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.XmlUtil;
import org.eclipse.cdt.internal.core.parser.util.WeakHashSet;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@ -50,6 +51,14 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$ private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$
private static WeakHashSet<List<ICLanguageSettingEntry>> listLSEPool = new WeakHashSet<List<ICLanguageSettingEntry>>() {
@Override
public synchronized List<ICLanguageSettingEntry> add(List<ICLanguageSettingEntry> list) {
return super.add(list);
}
};
private Map<String, // languageId private Map<String, // languageId
Map<String, // resource project path Map<String, // resource project path
@ -120,7 +129,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
langMap = new HashMap<String, List<ICLanguageSettingEntry>>(); langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
fStorage.put(languageId, langMap); fStorage.put(languageId, langMap);
} }
List<ICLanguageSettingEntry> sortedEntries = sortEntries(entries); List<ICLanguageSettingEntry> sortedEntries = listLSEPool.add(Collections.unmodifiableList(sortEntries(entries)));
langMap.put(rcProjectPath, sortedEntries); langMap.put(rcProjectPath, sortedEntries);
} else { } else {
// do not keep nulls in the tables // do not keep nulls in the tables
@ -170,6 +179,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* Note that this list is unmodifiable.
*/ */
@Override @Override
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) { public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
@ -178,7 +189,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null; String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null;
List<ICLanguageSettingEntry> entries = langMap.get(rcProjectPath); List<ICLanguageSettingEntry> entries = langMap.get(rcProjectPath);
if (entries!=null) if (entries!=null)
return Collections.unmodifiableList(entries); return entries;
} }
if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) { if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) {
@ -408,8 +419,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entrySetRc) { for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entrySetRc) {
String rcProjectPath = entryRc.getKey(); String rcProjectPath = entryRc.getKey();
List<ICLanguageSettingEntry> lsEntries = entryRc.getValue(); List<ICLanguageSettingEntry> lsEntries = entryRc.getValue();
List<ICLanguageSettingEntry> lsEntriesClone = new ArrayList<ICLanguageSettingEntry>(lsEntries); // don't need to clone entries, they are from the pool
mapRcClone.put(rcProjectPath, lsEntriesClone); mapRcClone.put(rcProjectPath, lsEntries);
} }
// mapLangClone.put(langId, mapRcClone); // mapLangClone.put(langId, mapRcClone);
storageClone.put(langId, mapRcClone); storageClone.put(langId, mapRcClone);