### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java,v retrieving revision 1.30 diff -u -r1.30 DefaultCommentMapper.java --- dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java 24 Nov 2006 13:33:40 -0000 1.30 +++ dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java 5 Apr 2007 09:42:05 -0000 @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.core.dom; -import java.util.HashMap; - import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.InvalidInputException; import org.eclipse.jdt.internal.compiler.parser.Scanner; @@ -541,7 +539,9 @@ class CommentMapperVisitor extends DefaultASTVisitor { - HashMap waitingSiblings = new HashMap(10); + ASTNode topSiblingParent = null; + ASTNode[] siblings = new ASTNode[10]; + int siblingPtr = -1; protected boolean visitNode(ASTNode node) { @@ -550,7 +550,7 @@ int previousEnd = parent.getStartPosition(); // Look for sibling node - ASTNode sibling = (ASTNode) this.waitingSiblings.get(parent); + ASTNode sibling = parent == this.topSiblingParent ? (ASTNode) this.siblings[this.siblingPtr] : null; if (sibling != null) { // Found one previous sibling, so compute its trailing comments using current node start position try { @@ -573,7 +573,12 @@ } // Store current node as waiting sibling for its parent - this.waitingSiblings.put(parent, node); + if (this.topSiblingParent != parent) { + this.topSiblingParent = parent; + if (this.siblings.length == ++this.siblingPtr) + System.arraycopy(this.siblings, 0, this.siblings = new ASTNode[this.siblingPtr*2], 0, this.siblingPtr); + } + this.siblings[this.siblingPtr] = node; // We're always ok to visit sub-levels return true; @@ -582,7 +587,7 @@ protected void endVisitNode(ASTNode node) { // Look if a child node is waiting for trailing comments computing - ASTNode sibling = (ASTNode) this.waitingSiblings.get(node); + ASTNode sibling = this.topSiblingParent == node ? (ASTNode) this.siblings[this.siblingPtr] : null; if (sibling != null) { try { storeTrailingComments(sibling, node.getStartPosition()+node.getLength()-1, true); @@ -590,6 +595,12 @@ // Give up extended ranges at this level if unexpected exception happens... } } + // Remove sibling if needed + if (this.topSiblingParent != null /*not a CompilationUnit*/ + && this.topSiblingParent == node) { + this.siblingPtr--; + this.topSiblingParent = node.getParent(); + } } public boolean visit ( CompilationUnit node) {