mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-27 19:05:38 +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.Map.Entry;
|
||||||
import java.util.Set;
|
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.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
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.core.settings.model.util.LanguageSettingEntriesSerializer;
|
||||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -264,28 +259,11 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ICLanguageSettingEntry entry = null;
|
String settingValue = null;
|
||||||
switch (LanguageSettingEntriesSerializer.stringToKind(settingKind)) {
|
int kind = LanguageSettingEntriesSerializer.stringToKind(settingKind);
|
||||||
case ICSettingEntry.INCLUDE_PATH:
|
if (kind == ICSettingEntry.MACRO)
|
||||||
entry = new CIncludePathEntry(settingName, flags);
|
settingValue = XmlUtil.determineAttributeValue(parentElement, ATTR_VALUE);
|
||||||
break;
|
ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry(kind, settingName, settingValue, null, flags);
|
||||||
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;
|
|
||||||
}
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,30 +51,31 @@ public abstract class ACSettingEntry implements ICSettingEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other){
|
public boolean equals(Object obj) {
|
||||||
if(other == this)
|
if (this == obj)
|
||||||
return true;
|
return true;
|
||||||
|
if (obj == null)
|
||||||
if(!(other instanceof ACSettingEntry))
|
|
||||||
return false;
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
ACSettingEntry e = (ACSettingEntry)other;
|
|
||||||
|
|
||||||
if(getKind() != e.getKind())
|
|
||||||
return false;
|
return false;
|
||||||
|
ACSettingEntry other = (ACSettingEntry) obj;
|
||||||
if(fFlags != e.fFlags)
|
if (fFlags != other.fFlags)
|
||||||
return false;
|
return false;
|
||||||
|
if (fName == null) {
|
||||||
if(!fName.equals(e.fName))
|
if (other.fName != null)
|
||||||
|
return false;
|
||||||
|
} else if (!fName.equals(other.fName))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode(){
|
public int hashCode() {
|
||||||
return getKind() + fFlags + fName.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() {
|
public int getFlags() {
|
||||||
|
|
|
@ -34,15 +34,28 @@ public final class CMacroEntry extends ACSettingEntry implements ICMacroEntry{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object obj) {
|
||||||
if(!super.equals(other))
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (!super.equals(obj))
|
||||||
return false;
|
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
|
@Override
|
||||||
public int hashCode() {
|
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
|
@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.CTargetPlatformData;
|
||||||
import org.eclipse.cdt.core.settings.model.extension.impl.CDataFactory;
|
import org.eclipse.cdt.core.settings.model.extension.impl.CDataFactory;
|
||||||
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData;
|
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.cdt.internal.core.settings.model.ExceptionFactory;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.ProjectScope;
|
import org.eclipse.core.resources.ProjectScope;
|
||||||
|
@ -74,6 +75,14 @@ public class CDataUtil {
|
||||||
|
|
||||||
private static Random randomNumber;
|
private static Random randomNumber;
|
||||||
public static final String[] EMPTY_STRING_ARRAY = new String[0];
|
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(){
|
public static int genRandomNumber(){
|
||||||
if (randomNumber == null) {
|
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){
|
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){
|
switch (kind){
|
||||||
case ICLanguageSettingEntry.INCLUDE_PATH:
|
case ICLanguageSettingEntry.INCLUDE_PATH:
|
||||||
return new CIncludePathEntry(name, flags);
|
entry = new CIncludePathEntry(name, flags);
|
||||||
|
break;
|
||||||
case ICLanguageSettingEntry.MACRO:
|
case ICLanguageSettingEntry.MACRO:
|
||||||
return new CMacroEntry(name, value, flags);
|
entry = new CMacroEntry(name, value, flags);
|
||||||
|
break;
|
||||||
case ICLanguageSettingEntry.INCLUDE_FILE:
|
case ICLanguageSettingEntry.INCLUDE_FILE:
|
||||||
return new CIncludeFileEntry(name, flags);
|
entry = new CIncludeFileEntry(name, flags);
|
||||||
|
break;
|
||||||
case ICLanguageSettingEntry.MACRO_FILE:
|
case ICLanguageSettingEntry.MACRO_FILE:
|
||||||
return new CMacroFileEntry(name, flags);
|
entry = new CMacroFileEntry(name, flags);
|
||||||
|
break;
|
||||||
case ICLanguageSettingEntry.LIBRARY_PATH:
|
case ICLanguageSettingEntry.LIBRARY_PATH:
|
||||||
return new CLibraryPathEntry(name, flags);
|
entry = new CLibraryPathEntry(name, flags);
|
||||||
|
break;
|
||||||
case ICLanguageSettingEntry.LIBRARY_FILE:
|
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:
|
case ICLanguageSettingEntry.OUTPUT_PATH:
|
||||||
return new COutputEntry(name, exclusionPatterns, flags);
|
entry = new COutputEntry(name, exclusionPatterns, flags);
|
||||||
|
break;
|
||||||
case ICLanguageSettingEntry.SOURCE_PATH:
|
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) {
|
public static String[] getSourceExtensions(IProject project, CLanguageData data) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue