mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-16 12:45:41 +02:00
Improve performance for storing large classes in index, 287907.
This commit is contained in:
parent
72a7fa5cd0
commit
3a0a069fb7
2 changed files with 47 additions and 28 deletions
|
@ -50,12 +50,42 @@ import org.eclipse.cdt.internal.core.index.IIndexScope;
|
|||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Represents the class scope for a class stored in the index.
|
||||
*/
|
||||
class PDOMCPPClassScope implements ICPPClassScope, IIndexScope {
|
||||
private static final class PopulateMap implements IPDOMVisitor {
|
||||
private final CharArrayMap<List<PDOMBinding>> fResult;
|
||||
private PopulateMap(CharArrayMap<List<PDOMBinding>> result) {
|
||||
fResult = result;
|
||||
}
|
||||
|
||||
public boolean visit(IPDOMNode node) throws CoreException {
|
||||
if (node instanceof PDOMBinding) {
|
||||
final PDOMBinding binding= (PDOMBinding) node;
|
||||
final char[] nchars = binding.getNameCharArray();
|
||||
List<PDOMBinding> list= fResult.get(nchars);
|
||||
if (list == null) {
|
||||
list= new ArrayList<PDOMBinding>();
|
||||
fResult.put(nchars, list);
|
||||
}
|
||||
list.add(binding);
|
||||
try {
|
||||
if (binding instanceof ICompositeType && ((ICompositeType) binding).isAnonymous()) {
|
||||
return true; // visit children
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void leave(IPDOMNode node){}
|
||||
}
|
||||
|
||||
private static final IndexFilter CONVERSION_FILTER = new DeclaredBindingsFilter(ILinkage.CPP_LINKAGE_ID, true, false) {
|
||||
@Override
|
||||
public boolean acceptBinding(IBinding binding) throws CoreException {
|
||||
|
@ -186,6 +216,19 @@ class PDOMCPPClassScope implements ICPPClassScope, IIndexScope {
|
|||
}
|
||||
}
|
||||
|
||||
public static void updateCache(IPDOMCPPClassType ct, PDOMNode member) throws CoreException {
|
||||
if (member instanceof PDOMBinding) {
|
||||
final Long key= ct.getRecord() + PDOMCPPLinkage.CACHE_MEMBERS;
|
||||
final PDOM pdom = ct.getPDOM();
|
||||
@SuppressWarnings("unchecked")
|
||||
Reference<CharArrayMap<List<PDOMBinding>>> cached= (Reference<CharArrayMap<List<PDOMBinding>>>) pdom.getCachedResult(key);
|
||||
CharArrayMap<List<PDOMBinding>> map= cached == null ? null : cached.get();
|
||||
if (map != null) {
|
||||
new PopulateMap(map).visit(member);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CharArrayMap<List<PDOMBinding>> getBindingMap(IPDOMCPPClassType ct) throws CoreException {
|
||||
final Long key= ct.getRecord() + PDOMCPPLinkage.CACHE_MEMBERS;
|
||||
final PDOM pdom = ct.getPDOM();
|
||||
|
@ -195,34 +238,10 @@ class PDOMCPPClassScope implements ICPPClassScope, IIndexScope {
|
|||
|
||||
if (map == null) {
|
||||
// there is no cache, build it:
|
||||
final CharArrayMap<List<PDOMBinding>> result= new CharArrayMap<List<PDOMBinding>>();
|
||||
IPDOMVisitor visitor= new IPDOMVisitor() {
|
||||
public boolean visit(IPDOMNode node) throws CoreException {
|
||||
if (node instanceof PDOMBinding) {
|
||||
final PDOMBinding binding= (PDOMBinding) node;
|
||||
final char[] nchars = binding.getNameCharArray();
|
||||
List<PDOMBinding> list= result.get(nchars);
|
||||
if (list == null) {
|
||||
list= new ArrayList<PDOMBinding>();
|
||||
result.put(nchars, list);
|
||||
}
|
||||
list.add(binding);
|
||||
|
||||
try {
|
||||
if (binding instanceof ICompositeType && ((ICompositeType) binding).isAnonymous()) {
|
||||
return true; // visit children
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void leave(IPDOMNode node){}
|
||||
};
|
||||
|
||||
map= new CharArrayMap<List<PDOMBinding>>();
|
||||
IPDOMVisitor visitor= new PopulateMap(map);
|
||||
visitor.visit(ct);
|
||||
ct.acceptUncached(visitor);
|
||||
map= result;
|
||||
pdom.putCachedResult(key, new SoftReference<CharArrayMap<?>>(map));
|
||||
}
|
||||
return map;
|
||||
|
|
|
@ -119,10 +119,10 @@ class PDOMCPPClassType extends PDOMCPPBinding implements IPDOMCPPClassType, IPDO
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addChild(PDOMNode member) throws CoreException {
|
||||
getPDOM().removeCachedResult(record + PDOMCPPLinkage.CACHE_MEMBERS);
|
||||
public final void addChild(PDOMNode member) throws CoreException {
|
||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBERLIST);
|
||||
list.addMember(member);
|
||||
PDOMCPPClassScope.updateCache(this, member);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue