From 50f8dcd8aa91bd09f085a91900abaf0040f792f9 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 15 Dec 2004 21:12:51 +0000 Subject: [PATCH] Address some performance issues regarding opening inclusions in the resource tree for both the new and old parser framework. --- .../parser/AbstractGNUSourceCodeParser.java | 9 ++- .../core/dom/parser/c/GNUCSourceParser.java | 7 +++ .../dom/parser/cpp/GNUCPPSourceParser.java | 7 +++ .../scanner2/FileCodeReaderFactory.java | 58 +++++++++++++++++++ .../eclipse/cdt/core/parser/ParserUtil.java | 12 ++-- 5 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FileCodeReaderFactory.java diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 194b043ac26..2d31f1513f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -390,9 +390,16 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { + (++parseCount) + ": " //$NON-NLS-1$ + (System.currentTimeMillis() - startTime) + "ms" //$NON-NLS-1$ + (parsePassed ? "" : " - parse failure")); //$NON-NLS-1$ //$NON-NLS-2$ - return getTranslationUnit(); + IASTTranslationUnit result = getTranslationUnit(); + nullifyTranslationUnit(); + return result; } + /** + * + */ + protected abstract void nullifyTranslationUnit(); + protected void skipOverCompoundStatement() throws BacktrackException, EndOfFileException { // speed up the parser by skiping the body diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 83d8be8e6fc..9feaea26fd5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -2101,4 +2101,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#nullifyTranslationUnit() + */ + protected void nullifyTranslationUnit() { + translationUnit = null; + } + } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 4b2524c44c2..f1628378e26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -4497,5 +4497,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return new CPPASTTryBlockStatement(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#nullifyTranslationUnit() + */ + protected void nullifyTranslationUnit() { + translationUnit = null; + } + } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FileCodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FileCodeReaderFactory.java new file mode 100644 index 00000000000..a60a52e50a1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FileCodeReaderFactory.java @@ -0,0 +1,58 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser.scanner2; + +import org.eclipse.cdt.core.dom.ICodeReaderFactory; +import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.internal.core.parser.InternalParserUtil; + +/** + * @author jcamelon + */ +public class FileCodeReaderFactory implements ICodeReaderFactory { + + private static FileCodeReaderFactory instance; + + private FileCodeReaderFactory() + { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getUniqueIdentifier() + */ + public int getUniqueIdentifier() { + return 3; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForTranslationUnit(java.lang.String) + */ + public CodeReader createCodeReaderForTranslationUnit(String path) { + return InternalParserUtil.createFileReader(path); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String) + */ + public CodeReader createCodeReaderForInclusion(String path) { + return InternalParserUtil.createFileReader(path); + } + + /** + * @return + */ + public static FileCodeReaderFactory getInstance() { + if( instance == null ) + instance = new FileCodeReaderFactory(); + return instance; + } + +} diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java index 64cbac98ab9..a8aa9e98d12 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.internal.core.parser.ParserLogService; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -98,11 +99,14 @@ public class ParserUtil return null; IPath path = new Path( finalPath ); - if( workspace.getRoot().getLocation().isPrefixOf( path ) ) - path = path.removeFirstSegments(workspace.getRoot().getLocation().segmentCount() ); + IWorkspaceRoot root = workspace.getRoot(); + if( root.getLocation().isPrefixOf( path ) ) + path = path.removeFirstSegments(root.getLocation().segmentCount() ); - IResource resultingResource = workspace.getRoot().findMember(path); - return resultingResource; + IResource resultingResource = root.getFile(path); + if( resultingResource.exists() ) + return resultingResource; + return null; } /**