[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] DOM Space Optimization
|
CORE
Fixed Bug 36243 DomBuilder Offsetable List
No tests provided as this was defect was just a reminder of a need for a
particular optimization.
JohnC
Index: dom/org/eclipse/cdt/internal/core/dom/TranslationUnit.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TranslationUnit.java,v
retrieving revision 1.6
diff -u -r1.6 TranslationUnit.java
--- dom/org/eclipse/cdt/internal/core/dom/TranslationUnit.java 8 Apr 2003 21:30:53 -0000 1.6
+++ dom/org/eclipse/cdt/internal/core/dom/TranslationUnit.java 11 Apr 2003 15:58:08 -0000
@@ -2,8 +2,10 @@
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.NoSuchElementException;
/**
@@ -13,11 +15,9 @@
private List declarations = new LinkedList();
private List macros = new ArrayList();
private List inclusions = new ArrayList();
- private List offsetables = new ArrayList();
public void addDeclaration(Declaration declaration) {
declarations.add(declaration);
- offsetables.add(declaration);
}
public List getDeclarations() {
@@ -40,21 +40,117 @@
public void addMacro(Macro macro) {
macros.add(macro);
- offsetables.add(macro);
}
public void addInclusion(Inclusion inclusion) {
inclusions.add(inclusion);
- offsetables.add(inclusion);
}
- /**
- * Returns the offsetables.
- * @return List
- */
- public List getOffsetables() {
- return Collections.unmodifiableList( offsetables );
+ public Iterator iterateOffsetableElements()
+ {
+ return new OffsetableIterator();
+ }
+
+ public class OffsetableIterator implements Iterator
+ {
+ private final Iterator declarationIter;
+ private final Iterator inclusionIter;
+ private final Iterator macroIter;
+
+ private IOffsetable currentMacro = null, currentInclusion= null, currentDeclaration= null;
+
+ public OffsetableIterator()
+ {
+ declarationIter = getDeclarations().iterator();
+ inclusionIter = getInclusions().iterator();
+ macroIter = getMacros().iterator();
+ updateInclusionIterator();
+ updateDeclarationIterator();
+ updateMacroIterator();
+ }
+
+ private Object updateDeclarationIterator()
+ {
+ Object offsetable = currentDeclaration;
+ currentDeclaration = ( declarationIter.hasNext() ) ? (IOffsetable)declarationIter.next() : null;
+ return offsetable;
+ }
+
+ private Object updateMacroIterator()
+ {
+ Object offsetable = currentMacro;
+ currentMacro = ( macroIter.hasNext() ) ? (IOffsetable)macroIter.next() : null;
+ return offsetable;
+ }
+
+ private Object updateInclusionIterator()
+ {
+ Object offsetable = currentInclusion;
+ currentInclusion = ( inclusionIter.hasNext() ) ? (IOffsetable)inclusionIter.next() : null;
+ return offsetable;
+ }
+ /* (non-Javadoc)
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return (( currentMacro == null && currentInclusion == null && currentDeclaration == null ) ?
+ false : true);
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ // case 1: all are null
+ if( ! hasNext() )
+ throw new NoSuchElementException();
+
+ // case 2: two of three are null
+ if( currentMacro == null && currentInclusion == null )
+ return updateDeclarationIterator();
+ if( currentDeclaration == null && currentInclusion == null )
+ return updateMacroIterator();
+ if( currentMacro == null && currentDeclaration == null )
+ return updateInclusionIterator();
+
+ // case 3: 1 is null
+ if( currentMacro == null )
+ if( currentDeclaration.getStartingOffset() < currentInclusion.getStartingOffset() )
+ return updateDeclarationIterator();
+ else
+ return updateInclusionIterator();
+
+ if( currentInclusion == null )
+ if( currentDeclaration.getStartingOffset() < currentMacro.getStartingOffset() )
+ return updateDeclarationIterator();
+ else
+ return updateMacroIterator();
+
+ if( currentDeclaration == null )
+ if( currentInclusion.getStartingOffset() < currentMacro.getStartingOffset() )
+ return updateInclusionIterator();
+ else
+ return updateMacroIterator();
+
+ // case 4: none are null
+ if( currentInclusion.getStartingOffset() < currentMacro.getStartingOffset() &&
+ currentInclusion.getStartingOffset() < currentDeclaration.getStartingOffset() )
+ return updateInclusionIterator();
+
+ if( currentMacro.getStartingOffset() < currentInclusion.getStartingOffset() &&
+ currentMacro.getStartingOffset() < currentDeclaration.getStartingOffset() )
+ return updateMacroIterator();
+ // only remaining case
+ return updateDeclarationIterator();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException( "OffsetableIterator is a const iterator");
+ }
}
}
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.26
diff -u -r1.26 ChangeLog
--- parser/ChangeLog 11 Apr 2003 14:42:24 -0000 1.26
+++ parser/ChangeLog 11 Apr 2003 15:58:08 -0000
@@ -1,3 +1,6 @@
+2003-04-11 John Camelon
+ Fixed Bug 36243 DomBuilder Offsetable List
+
2003-04-10 John Camelon
Fixed Bug36237 Parser fails on casts in ctor initializer.
Added AccessSpecifier to TemplateDeclaration.
Index: parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java,v
retrieving revision 1.5
diff -u -r1.5 CModelBuilder.java
--- parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java 11 Apr 2003 14:36:51 -0000 1.5
+++ parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java 11 Apr 2003 15:58:09 -0000
@@ -65,8 +65,7 @@
}
protected void generateModelElements(TranslationUnit tu){
- List offsetables = tu.getOffsetables();
- Iterator i = offsetables.iterator();
+ Iterator i = tu.iterateOffsetableElements();
while (i.hasNext()){
IOffsetable offsetable = (IOffsetable)i.next();
if(offsetable instanceof Inclusion){