mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
Use WeakHashMap to keep LSE in common pool.
This commit is contained in:
parent
5e5f1a61f7
commit
7f3232a959
4 changed files with 68 additions and 56 deletions
|
@ -19,15 +19,10 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CLibraryFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CLibraryPathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
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.LanguageSettingEntriesSerializer;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
@ -264,28 +259,11 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
|
||||
}
|
||||
|
||||
ICLanguageSettingEntry entry = null;
|
||||
switch (LanguageSettingEntriesSerializer.stringToKind(settingKind)) {
|
||||
case ICSettingEntry.INCLUDE_PATH:
|
||||
entry = new CIncludePathEntry(settingName, flags);
|
||||
break;
|
||||
case ICSettingEntry.INCLUDE_FILE:
|
||||
entry = new CIncludeFileEntry(settingName, flags);
|
||||
break;
|
||||
case ICSettingEntry.MACRO:
|
||||
String settingValue = XmlUtil.determineAttributeValue(parentElement, ATTR_VALUE);
|
||||
entry = new CMacroEntry(settingName, settingValue, flags);
|
||||
break;
|
||||
case ICSettingEntry.MACRO_FILE:
|
||||
entry = new CMacroFileEntry(settingName, flags);
|
||||
break;
|
||||
case ICSettingEntry.LIBRARY_PATH:
|
||||
entry = new CLibraryPathEntry(settingName, flags);
|
||||
break;
|
||||
case ICSettingEntry.LIBRARY_FILE:
|
||||
entry = new CLibraryFileEntry(settingName, flags);
|
||||
break;
|
||||
}
|
||||
String settingValue = null;
|
||||
int kind = LanguageSettingEntriesSerializer.stringToKind(settingKind);
|
||||
if (kind == ICSettingEntry.MACRO)
|
||||
settingValue = XmlUtil.determineAttributeValue(parentElement, ATTR_VALUE);
|
||||
ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry(kind, settingName, settingValue, null, flags);
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,30 +51,31 @@ public abstract class ACSettingEntry implements ICSettingEntry {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other){
|
||||
if(other == this)
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if(!(other instanceof ACSettingEntry))
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
ACSettingEntry e = (ACSettingEntry)other;
|
||||
|
||||
if(getKind() != e.getKind())
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
if(fFlags != e.fFlags)
|
||||
ACSettingEntry other = (ACSettingEntry) obj;
|
||||
if (fFlags != other.fFlags)
|
||||
return false;
|
||||
|
||||
if(!fName.equals(e.fName))
|
||||
if (fName == null) {
|
||||
if (other.fName != null)
|
||||
return false;
|
||||
} else if (!fName.equals(other.fName))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return getKind() + fFlags + fName.hashCode();
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + fFlags;
|
||||
result = prime * result + ((fName == null) ? 0 : fName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
|
|
|
@ -34,15 +34,28 @@ public final class CMacroEntry extends ACSettingEntry implements ICMacroEntry{
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if(!super.equals(other))
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
return fValue.equals(((CMacroEntry)other).fValue);
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
CMacroEntry other = (CMacroEntry) obj;
|
||||
if (fValue == null) {
|
||||
if (other.fValue != null)
|
||||
return false;
|
||||
} else if (!fValue.equals(other.fValue))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() + fValue.hashCode();
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((fValue == null) ? 0 : fValue.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.eclipse.cdt.core.settings.model.extension.CResourceData;
|
|||
import org.eclipse.cdt.core.settings.model.extension.CTargetPlatformData;
|
||||
import org.eclipse.cdt.core.settings.model.extension.impl.CDataFactory;
|
||||
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData;
|
||||
import org.eclipse.cdt.internal.core.parser.util.WeakHashSet;
|
||||
import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
|
@ -74,6 +75,14 @@ public class CDataUtil {
|
|||
|
||||
private static Random randomNumber;
|
||||
public static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
private static WeakHashSet<ICSettingEntry> languageSettingsPool = new WeakHashSet<ICSettingEntry>() {
|
||||
@Override
|
||||
public synchronized ICSettingEntry add(ICSettingEntry entry) {
|
||||
return super.add(entry);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static int genRandomNumber(){
|
||||
if (randomNumber == null) {
|
||||
|
@ -301,25 +310,36 @@ public class CDataUtil {
|
|||
|
||||
|
||||
public static ICSettingEntry createEntry(int kind, String name, String value, IPath[] exclusionPatterns, int flags, IPath srcPath, IPath srcRootPath, IPath srcPrefixMapping){
|
||||
ICSettingEntry entry = null;
|
||||
switch (kind){
|
||||
case ICLanguageSettingEntry.INCLUDE_PATH:
|
||||
return new CIncludePathEntry(name, flags);
|
||||
entry = new CIncludePathEntry(name, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.MACRO:
|
||||
return new CMacroEntry(name, value, flags);
|
||||
entry = new CMacroEntry(name, value, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.INCLUDE_FILE:
|
||||
return new CIncludeFileEntry(name, flags);
|
||||
entry = new CIncludeFileEntry(name, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.MACRO_FILE:
|
||||
return new CMacroFileEntry(name, flags);
|
||||
entry = new CMacroFileEntry(name, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.LIBRARY_PATH:
|
||||
return new CLibraryPathEntry(name, flags);
|
||||
entry = new CLibraryPathEntry(name, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.LIBRARY_FILE:
|
||||
return new CLibraryFileEntry(name, flags, srcPath, srcRootPath, srcPrefixMapping);
|
||||
entry = new CLibraryFileEntry(name, flags, srcPath, srcRootPath, srcPrefixMapping);
|
||||
break;
|
||||
case ICLanguageSettingEntry.OUTPUT_PATH:
|
||||
return new COutputEntry(name, exclusionPatterns, flags);
|
||||
entry = new COutputEntry(name, exclusionPatterns, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.SOURCE_PATH:
|
||||
return new CSourceEntry(name, exclusionPatterns, flags);
|
||||
entry = new CSourceEntry(name, exclusionPatterns, flags);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
return languageSettingsPool.add(entry);
|
||||
}
|
||||
|
||||
public static String[] getSourceExtensions(IProject project, CLanguageData data) {
|
||||
|
|
Loading…
Add table
Reference in a new issue