diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog
index 6f4a371fb15..77f43d31938 100644
--- a/core/org.eclipse.cdt.core/ChangeLog
+++ b/core/org.eclipse.cdt.core/ChangeLog
@@ -1,3 +1,8 @@
+2004-04-12 Hoda Amer
+ CModelBuilder and scalability problems: Building the CModel takes a long time
+ when translation unit has lots of children (25,000 children taking ~ 45 sec to build model).
+ Revising Parent.addChild() and TranslationUnit.removeChildren() (now 25,000 children taking ~ 160 ms).
+
2004-04-07 David Inglis
Fixed event problem
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java
index 945ed1ccae8..8f5eeac0ad9 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java
@@ -213,9 +213,7 @@ public class CContainer extends Openable implements ICContainer {
//e.printStackTrace();
throw new CModelException(e);
}
- ICElement[] children = new ICElement[vChildren.size()];
- vChildren.toArray(children);
- info.setChildren(children);
+ info.setChildren(vChildren);
if (info instanceof CContainerInfo) {
((CContainerInfo) info).setNonCResources(null);
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java
index 24350c87e1c..ef4c15cddaf 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java
@@ -6,6 +6,8 @@ package org.eclipse.cdt.internal.core.model;
*/
import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IResource;
@@ -16,11 +18,6 @@ import org.eclipse.core.resources.IResource;
*/
class CElementInfo {
- /**
- * Shared empty collection used for efficiency.
- */
- static Object[] NO_NON_C_RESOURCES = new Object[] {};
-
protected CElement element;
/**
@@ -28,12 +25,7 @@ class CElementInfo {
* object. This is an empty array if this element has
* no children.
*/
- protected ICElement[] fChildren;
-
- /**
- * Shared empty collection used for efficiency.
- */
- protected static ICElement[] fgEmptyChildren = new ICElement[]{};
+ protected List fChildren;
/**
* Is the structure of this element known
@@ -45,7 +37,7 @@ class CElementInfo {
protected CElementInfo(CElement element) {
this.element = element;
- fChildren = fgEmptyChildren;
+ fChildren = new ArrayList();
}
protected CElement getElement() {
@@ -53,41 +45,21 @@ class CElementInfo {
}
protected void addChild(ICElement child) {
- if (fChildren == fgEmptyChildren) {
- setChildren(new ICElement[] {child});
- } else {
- if (!includesChild(child)) {
- setChildren(growAndAddToArray(fChildren, child));
- }
- }
+ fChildren.add(child);
}
protected ICElement[] getChildren() {
- return fChildren;
+ ICElement[] array= new ICElement[fChildren.size()];
+ return (ICElement[]) fChildren.toArray( array );
}
- /**
- * Adds the new element to a new array that contains all of the elements of the old array.
- * Returns the new array.
- */
- protected ICElement[] growAndAddToArray(ICElement[] array, ICElement addition) {
- ICElement[] old = array;
- array = new ICElement[old.length + 1];
- System.arraycopy(old, 0, array, 0, old.length);
- array[old.length] = addition;
- return array;
- }
/**
* Returns true
if this child is in my children collection
*/
- protected boolean includesChild(ICElement child) {
-
- for (int i= 0; i < fChildren.length; i++) {
- if (fChildren[i].equals(child)) {
- return true;
- }
- }
+ protected boolean includesChild(ICElement child) {
+ if(fChildren.contains(child))
+ return true;
return false;
}
@@ -98,42 +70,20 @@ class CElementInfo {
return fIsStructureKnown;
}
- /**
- * Returns an array with all the same elements as the specified array except for
- * the element to remove. Assumes that the deletion is contained in the array.
- */
- protected ICElement[] removeAndShrinkArray(ICElement[] array, ICElement deletion) {
- ICElement[] old = array;
- array = new ICElement[old.length - 1];
- int j = 0;
- for (int i = 0; i < old.length; i++) {
- if (!old[i].equals(deletion)) {
- array[j] = old[i];
- } else {
- System.arraycopy(old, i + 1, array, j, old.length - (i + 1));
- return array;
- }
- j++;
- }
- return array;
- }
-
protected void removeChild(ICElement child) {
- if (includesChild(child)) {
- setChildren(removeAndShrinkArray(fChildren, child));
- }
+ fChildren.remove(child);
}
protected void removeChildren () {
- fChildren = fgEmptyChildren;
+ fChildren.clear();
}
- protected void setChildren(ICElement[] children) {
- fChildren = children;
+ protected void setChildren(List children) {
+ fChildren.addAll(children);
}
protected boolean hasChildren() {
- return fChildren.length > 0;
+ return fChildren.size() > 0;
}
protected void setChanged() {
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
index 8fc5e0c150d..a1bb176662e 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
@@ -70,7 +70,7 @@ public class CModelBuilder {
private IASTCompilationUnit compilationUnit;
// indicator if the unit has parse errors
private boolean hasNoErrors = false;
-
+
public CModelBuilder(org.eclipse.cdt.internal.core.model.TranslationUnit tu) {
this.translationUnit = tu ;
this.newElements = new HashMap();
@@ -150,6 +150,7 @@ public class CModelBuilder {
public Map parse(boolean quickParseMode) throws Exception {
+ long startTime = System.currentTimeMillis();
try
{
compilationUnit = parse( translationUnit, quickParseMode, true);
@@ -160,7 +161,9 @@ public class CModelBuilder {
Util.debugLog( "Parse Exception in CModelBuilder", IDebugLogConstants.MODEL ); //$NON-NLS-1$
//e.printStackTrace();
}
- long startTime = System.currentTimeMillis();
+ Util.debugLog("CModel parsing: "+ ( System.currentTimeMillis() - startTime ) + "ms", IDebugLogConstants.MODEL); //$NON-NLS-1$ //$NON-NLS-2$
+
+ startTime = System.currentTimeMillis();
try
{
generateModelElements();
@@ -170,13 +173,12 @@ public class CModelBuilder {
catch( NullPointerException npe )
{
Util.debugLog( "NullPointer exception in CModelBuilder", IDebugLogConstants.MODEL); //$NON-NLS-1$
- //npe.printStackTrace();
}
// For the debuglog to take place, you have to call
// Util.setDebugging(true);
// Or set debug to true in the core plugin preference
- Util.debugLog("CModel build: "+ ( System.currentTimeMillis() - startTime ) + "ms", IDebugLogConstants.MODEL); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.debugLog("CModel building: "+ ( System.currentTimeMillis() - startTime ) + "ms", IDebugLogConstants.MODEL); //$NON-NLS-1$ //$NON-NLS-2$
return this.newElements;
}
@@ -344,6 +346,7 @@ public class CModelBuilder {
element.setLines( macro.getStartingLine(), macro.getEndingLine() );
this.newElements.put(element, element.getElementInfo());
return element;
+
}
private Namespace createNamespace(Parent parent, IASTNamespaceDefinition nsDef){
@@ -656,4 +659,10 @@ public class CModelBuilder {
return element;
}
+ /**
+ * @return Returns the newElements.
+ */
+ public Map getNewElements() {
+ return newElements;
+ }
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java
index 5fa93c3c9a9..39f22c9e27d 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java
@@ -41,7 +41,7 @@ public class CModelInfo extends OpenableInfo {
}
}
if (index == 0) {
- return NO_NON_C_RESOURCES;
+ return new Object[] {}; // NO_NON_C_RESOURCES
}
if (index < length) {
System.arraycopy(nonCProjects, 0, nonCProjects = new Object[index], 0, index);
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java
index e6939dd3e38..659cd168170 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java
@@ -4,6 +4,9 @@ package org.eclipse.cdt.internal.core.model;
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatus;
@@ -24,7 +27,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
* The elements related to the failure, or null
* if no elements are involved.
*/
- protected ICElement[] fElements = new ICElement[0];
+ protected List fElements = new ArrayList();
/**
* The path related to the failure, or null
* if no path is involved.
@@ -59,7 +62,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
*/
public CModelStatus(int code) {
super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$
- fElements= CElementInfo.fgEmptyChildren;
+ fElements.clear();
}
/**
@@ -68,7 +71,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
*/
public CModelStatus(int code, ICElement[] elements) {
super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$
- fElements= elements;
+ for(int i=0; i