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

Address some performance issues regarding opening inclusions in the resource tree for both the new and old parser framework.

This commit is contained in:
John Camelon 2004-12-15 21:12:51 +00:00
parent 495d10915b
commit 50f8dcd8aa
5 changed files with 88 additions and 5 deletions

View file

@ -390,9 +390,16 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
+ (++parseCount) + ": " //$NON-NLS-1$ + (++parseCount) + ": " //$NON-NLS-1$
+ (System.currentTimeMillis() - startTime) + "ms" //$NON-NLS-1$ + (System.currentTimeMillis() - startTime) + "ms" //$NON-NLS-1$
+ (parsePassed ? "" : " - parse failure")); //$NON-NLS-1$ //$NON-NLS-2$ + (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, protected void skipOverCompoundStatement() throws BacktrackException,
EndOfFileException { EndOfFileException {
// speed up the parser by skiping the body // speed up the parser by skiping the body

View file

@ -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;
}
} }

View file

@ -4497,5 +4497,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return new CPPASTTryBlockStatement(); return new CPPASTTryBlockStatement();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#nullifyTranslationUnit()
*/
protected void nullifyTranslationUnit() {
translationUnit = null;
}
} }

View file

@ -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;
}
}

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.internal.core.parser.ParserLogService;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -98,11 +99,14 @@ public class ParserUtil
return null; return null;
IPath path = new Path( finalPath ); IPath path = new Path( finalPath );
if( workspace.getRoot().getLocation().isPrefixOf( path ) ) IWorkspaceRoot root = workspace.getRoot();
path = path.removeFirstSegments(workspace.getRoot().getLocation().segmentCount() ); if( root.getLocation().isPrefixOf( path ) )
path = path.removeFirstSegments(root.getLocation().segmentCount() );
IResource resultingResource = workspace.getRoot().findMember(path); IResource resultingResource = root.getFile(path);
if( resultingResource.exists() )
return resultingResource; return resultingResource;
return null;
} }
/** /**