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

CModelBuilder and scalability problems

This commit is contained in:
Hoda Amer 2004-04-16 14:48:50 +00:00
parent 3dc5e212e0
commit 09739d577e
9 changed files with 64 additions and 18 deletions

View file

@ -1,3 +1,9 @@
2004-04-16 Hoda Amer
-CModelBuilder and scalability problems: Starting children list with initial size = 0
Now 25,000 element Translation unit takes 450 ms in CModelBuilder.
-Also removed class Parent implemention interface IParent as only elements that
could really be parents should implement it.
2004-04-15 Alain Magloire
Archive/BinaryContainer was not cleaned up.

View file

@ -35,5 +35,19 @@ public interface IParent {
*/
boolean hasChildren();
/**
* Adds a child to the current element.
* Implementations override this method to support children
*/
void addChild(ICElement member);
/**
* Removes a child from the current element children list.
* @param member
*/
void removeChild(ICElement member);
/**
* Clears the element's children list.
*
*/
void removeChildren ();
}

View file

@ -1,5 +1,7 @@
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.ICElement;
/*
* (c) Copyright IBM Corp. 2000, 2001.
@ -24,4 +26,12 @@ public class ArchiveContainerInfo extends OpenableInfo {
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CElementInfo#addChild(org.eclipse.cdt.core.model.ICElement)
*/
protected void addChild(ICElement child) {
if (!includesChild(child)) {
super.addChild(child);
}
}
}

View file

@ -1,5 +1,7 @@
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.ICElement;
/*
* (c) Copyright IBM Corp. 2000, 2001.
@ -24,4 +26,12 @@ public class BinaryContainerInfo extends OpenableInfo {
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CElementInfo#addChild(org.eclipse.cdt.core.model.ICElement)
*/
protected void addChild(ICElement child) {
if (!includesChild(child)) {
super.addChild(child);
}
}
}

View file

@ -398,6 +398,10 @@ public abstract class CElement extends PlatformObject implements ICElement {
CElement child = (CElement) children[i];
child.removeInfo();
}
// we have to remove children here
// to clear the children list before
// removing the entry from the cache.
((CElementInfo)info).removeChildren();
}
CModelManager.getDefault().removeInfo(this);
}

View file

@ -17,6 +17,11 @@ import org.eclipse.core.resources.IResource;
* Subclassed to carry properties for specific kinds of elements.
*/
class CElementInfo {
/**
* Shared empty collection used for efficiency.
*/
static Object[] NO_NON_C_RESOURCES = new Object[] {};
protected CElement element;
@ -25,7 +30,7 @@ class CElementInfo {
* object. This is an empty array if this element has
* no children.
*/
protected List fChildren;
private List fChildren;
/**
* Is the structure of this element known
@ -37,7 +42,8 @@ class CElementInfo {
protected CElementInfo(CElement element) {
this.element = element;
fChildren = new ArrayList();
// Array list starts with size = 0
fChildren = new ArrayList(0);
}
protected CElement getElement() {
@ -45,9 +51,9 @@ class CElementInfo {
}
protected void addChild(ICElement child) {
if (!fChildren.contains(child)) {
fChildren.add(child);
}
// Do not add a check if the child is contained here
// because it causes a performance bottle neck for large files.
fChildren.add(child);
}
protected ICElement[] getChildren() {

View file

@ -41,7 +41,7 @@ public class CModelInfo extends OpenableInfo {
}
}
if (index == 0) {
return new Object[] {}; // NO_NON_C_RESOURCES
return NO_NON_C_RESOURCES;
}
if (index < length) {
System.arraycopy(nonCProjects, 0, nonCProjects = new Object[index], 0, index);

View file

@ -9,9 +9,8 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IParent;
public abstract class Parent extends CElement implements IParent {
public abstract class Parent extends CElement {
public Parent (ICElement parent, String name, int type) {
super (parent, name, type);
@ -23,7 +22,7 @@ public abstract class Parent extends CElement implements IParent {
* Adds a child to the current element.
* Implementations override this method to support children
*/
protected void addChild(ICElement member) {
public void addChild(ICElement member) {
getElementInfo().addChild(member);
}
@ -31,11 +30,11 @@ public abstract class Parent extends CElement implements IParent {
* Removes a child to the current element.
* Implementations override this method to support children
*/
protected void removeChild(ICElement member) {
public void removeChild(ICElement member) {
getElementInfo().removeChild(member);
}
protected void removeChildren () {
public void removeChildren () {
getElementInfo().removeChildren();
}
@ -47,7 +46,7 @@ public abstract class Parent extends CElement implements IParent {
public ICElement[] getChildren() {
CElementInfo info = getElementInfo();
if (info != null)
return getElementInfo().getChildren();
return info.getChildren();
else
return new ICElement[]{};
}

View file

@ -26,9 +26,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
/**
* @see ITranslationUnit
@ -478,8 +475,8 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
*/
public Map parse(){
removeChildren(this);
final CModelBuilder modelBuilder = new CModelBuilder(this);
final boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode());
CModelBuilder modelBuilder = new CModelBuilder(this);
boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode());
try {
return modelBuilder.parse(quickParseMode);
} catch (Exception e) {