mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Indexer performance improvement: indexing nodes from external include files only once.
This commit is contained in:
parent
30b6f0e0af
commit
ab0ae772ae
8 changed files with 70 additions and 16 deletions
|
@ -1,3 +1,14 @@
|
||||||
|
2005-05-20 Vladimir Hirsl
|
||||||
|
Indexer performance improvement: indexing nodes from external include files only once.
|
||||||
|
|
||||||
|
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
|
||||||
|
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
|
||||||
|
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java
|
||||||
|
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java
|
||||||
|
* index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java
|
||||||
|
* index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java
|
||||||
|
* index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
|
||||||
|
|
||||||
2005-05-19 Vladimir Hirsl
|
2005-05-19 Vladimir Hirsl
|
||||||
Final fix for 95641: [Scanner Config] Per file scanner info not available for header files
|
Final fix for 95641: [Scanner Config] Per file scanner info not available for header files
|
||||||
and not compiled source files.
|
and not compiled source files.
|
||||||
|
|
|
@ -88,7 +88,11 @@ public class CGenerateIndexVisitor extends CASTVisitor {
|
||||||
* @throws DOMException
|
* @throws DOMException
|
||||||
*/
|
*/
|
||||||
private void processName(IASTName name) throws DOMException {
|
private void processName(IASTName name) throws DOMException {
|
||||||
IBinding binding = name.resolveBinding();
|
// Quick check to see if the name is in an already indexed external header file
|
||||||
|
if (IndexEncoderUtil.nodeInVisitedExternalHeader(name, indexer.getIndexer()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
IBinding binding = name.resolveBinding();
|
||||||
// check for IProblemBinding
|
// check for IProblemBinding
|
||||||
if (binding instanceof IProblemBinding) {
|
if (binding instanceof IProblemBinding) {
|
||||||
IProblemBinding problem = (IProblemBinding) binding;
|
IProblemBinding problem = (IProblemBinding) binding;
|
||||||
|
@ -99,6 +103,7 @@ public class CGenerateIndexVisitor extends CASTVisitor {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the location
|
// Get the location
|
||||||
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
|
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
|
|
|
@ -102,7 +102,11 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
||||||
* @throws DOMException
|
* @throws DOMException
|
||||||
*/
|
*/
|
||||||
private void processName(IASTName name) throws DOMException {
|
private void processName(IASTName name) throws DOMException {
|
||||||
IBinding binding = name.resolveBinding();
|
// Quick check to see if the name is in an already indexed external header file
|
||||||
|
if (IndexEncoderUtil.nodeInVisitedExternalHeader(name, indexer.getIndexer()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
IBinding binding = name.resolveBinding();
|
||||||
// check for IProblemBinding
|
// check for IProblemBinding
|
||||||
if (binding instanceof IProblemBinding) {
|
if (binding instanceof IProblemBinding) {
|
||||||
IProblemBinding problem = (IProblemBinding) binding;
|
IProblemBinding problem = (IProblemBinding) binding;
|
||||||
|
@ -114,7 +118,7 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the location
|
// Get the location
|
||||||
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
|
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
//Check to see if this reference actually occurs in the file being indexed
|
//Check to see if this reference actually occurs in the file being indexed
|
||||||
|
|
|
@ -64,11 +64,18 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
|
||||||
static int errorCount = 0;
|
static int errorCount = 0;
|
||||||
static Map errors = new HashMap();
|
static Map errors = new HashMap();
|
||||||
|
|
||||||
public DOMSourceIndexerRunner(IFile resource, SourceIndexer indexer) {
|
public DOMSourceIndexerRunner(IFile resource, SourceIndexer indexer) {
|
||||||
this.resourceFile = resource;
|
this.resourceFile = resource;
|
||||||
this.indexer = indexer;
|
this.indexer = indexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the indexer.
|
||||||
|
*/
|
||||||
|
public SourceIndexer getIndexer() {
|
||||||
|
return indexer;
|
||||||
|
}
|
||||||
|
|
||||||
public void setFileTypes(String[] fileTypes) {
|
public void setFileTypes(String[] fileTypes) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
@ -199,14 +206,14 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
|
||||||
for (int i = 0; i < extScanInfo.getIncludeFiles().length; i++) {
|
for (int i = 0; i < extScanInfo.getIncludeFiles().length; i++) {
|
||||||
String includeFile = extScanInfo.getIncludeFiles()[i];
|
String includeFile = extScanInfo.getIncludeFiles()[i];
|
||||||
/* See if this file has been encountered before */
|
/* See if this file has been encountered before */
|
||||||
indexer.haveEncounteredHeader(resourceFile.getProject().getFullPath(), new Path(includeFile));
|
indexer.haveEncounteredHeader(resourceFile.getProject().getFullPath(), new Path(includeFile), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (extScanInfo.getMacroFiles().length > 0) {
|
if (extScanInfo.getMacroFiles().length > 0) {
|
||||||
for (int i = 0; i < extScanInfo.getIncludeFiles().length; i++) {
|
for (int i = 0; i < extScanInfo.getIncludeFiles().length; i++) {
|
||||||
String macrosFile = extScanInfo.getMacroFiles()[i];
|
String macrosFile = extScanInfo.getMacroFiles()[i];
|
||||||
/* See if this file has been encountered before */
|
/* See if this file has been encountered before */
|
||||||
indexer.haveEncounteredHeader(resourceFile.getProject().getFullPath(), new Path(macrosFile));
|
indexer.haveEncounteredHeader(resourceFile.getProject().getFullPath(), new Path(macrosFile), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,6 +240,10 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
|
||||||
private void processNestedInclusions(int fileNumber, IASTInclusionNode[] inclusions, IASTInclusionNode parent) {
|
private void processNestedInclusions(int fileNumber, IASTInclusionNode[] inclusions, IASTInclusionNode parent) {
|
||||||
for (int i = 0; i < inclusions.length; i++) {
|
for (int i = 0; i < inclusions.length; i++) {
|
||||||
IASTInclusionNode inclusion = inclusions[i];
|
IASTInclusionNode inclusion = inclusions[i];
|
||||||
|
// Quick check to see if the name is in an already indexed external header file
|
||||||
|
if (IndexEncoderUtil.nodeInVisitedExternalHeader(inclusion.getIncludeDirective(), getIndexer()))
|
||||||
|
return;
|
||||||
|
|
||||||
String include = inclusion.getIncludeDirective().getPath();
|
String include = inclusion.getIncludeDirective().getPath();
|
||||||
|
|
||||||
if (areProblemMarkersEnabled()) {
|
if (areProblemMarkersEnabled()) {
|
||||||
|
@ -257,7 +268,7 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
|
||||||
IIndex.OFFSET);
|
IIndex.OFFSET);
|
||||||
|
|
||||||
/* See if this file has been encountered before */
|
/* See if this file has been encountered before */
|
||||||
indexer.haveEncounteredHeader(resourceFile.getProject().getFullPath(), new Path(include));
|
indexer.haveEncounteredHeader(resourceFile.getProject().getFullPath(), new Path(include), true);
|
||||||
|
|
||||||
// recurse
|
// recurse
|
||||||
processNestedInclusions(fileNumber, inclusion.getNestedInclusions(), inclusion);
|
processNestedInclusions(fileNumber, inclusion.getNestedInclusions(), inclusion);
|
||||||
|
@ -270,7 +281,11 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
|
||||||
private void processMacroDefinitions(IASTPreprocessorMacroDefinition[] macroDefinitions) {
|
private void processMacroDefinitions(IASTPreprocessorMacroDefinition[] macroDefinitions) {
|
||||||
for (int i = 0; i < macroDefinitions.length; i++) {
|
for (int i = 0; i < macroDefinitions.length; i++) {
|
||||||
IASTName macro = macroDefinitions[i].getName();
|
IASTName macro = macroDefinitions[i].getName();
|
||||||
// Get the location
|
// Quick check to see if the macro is in an already indexed external header file
|
||||||
|
if (IndexEncoderUtil.nodeInVisitedExternalHeader(macro, getIndexer()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Get the location
|
||||||
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(macro);
|
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(macro);
|
||||||
int fileNumber = IndexEncoderUtil.calculateIndexFlags(this, loc);
|
int fileNumber = IndexEncoderUtil.calculateIndexFlags(this, loc);
|
||||||
IndexerOutputWrapper.addNameDecl(getOutput(),
|
IndexerOutputWrapper.addNameDecl(getOutput(),
|
||||||
|
@ -290,6 +305,9 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
|
||||||
private void processPreprocessorProblems(IASTProblem[] preprocessorProblems) {
|
private void processPreprocessorProblems(IASTProblem[] preprocessorProblems) {
|
||||||
for (int i = 0; i < preprocessorProblems.length; i++) {
|
for (int i = 0; i < preprocessorProblems.length; i++) {
|
||||||
IASTProblem problem = preprocessorProblems[i];
|
IASTProblem problem = preprocessorProblems[i];
|
||||||
|
// Quick check to see if the macro is in an already indexed external header file
|
||||||
|
if (IndexEncoderUtil.nodeInVisitedExternalHeader(problem, getIndexer()))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (areProblemMarkersEnabled() && shouldRecordProblem(problem)) {
|
if (areProblemMarkersEnabled() && shouldRecordProblem(problem)) {
|
||||||
// Get the location
|
// Get the location
|
||||||
|
|
|
@ -15,7 +15,9 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
|
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
|
||||||
|
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
public class IndexEncoderUtil {
|
public class IndexEncoderUtil {
|
||||||
|
@ -83,4 +85,19 @@ public class IndexEncoderUtil {
|
||||||
return fileLoc;
|
return fileLoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean nodeInExternalHeader(IASTNode node) {
|
||||||
|
String fileName = node.getContainingFilename();
|
||||||
|
return (CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName)) == null)
|
||||||
|
? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean nodeInVisitedExternalHeader(IASTNode node, SourceIndexer indexer) {
|
||||||
|
String fileName = node.getContainingFilename();
|
||||||
|
IPath filePath = new Path(fileName);
|
||||||
|
IPath projectPath = indexer.getProject().getFullPath();
|
||||||
|
|
||||||
|
return (CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName)) == null) &&
|
||||||
|
indexer.haveEncounteredHeader(projectPath, filePath, false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public abstract class AddFileToIndex extends IndexRequest {
|
||||||
|
|
||||||
/* See if this file has been encountered before */
|
/* See if this file has been encountered before */
|
||||||
if (type.isHeader() &&
|
if (type.isHeader() &&
|
||||||
indexer.haveEncounteredHeader(resourceProject.getFullPath(),resource.getLocation()))
|
indexer.haveEncounteredHeader(resourceProject.getFullPath(),resource.getLocation(), true))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/* ensure no concurrent write access to index */
|
/* ensure no concurrent write access to index */
|
||||||
|
|
|
@ -152,14 +152,11 @@ public class SourceIndexer extends AbstractCExtension implements ICDTIndexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the index for a given project, according to the following algorithm:
|
*
|
||||||
* - if index is already in memory: answers this one back
|
|
||||||
* - if (reuseExistingFile) then read it and return this index and record it in memory
|
|
||||||
* - if (createIfMissing) then create a new empty index and record it in memory
|
|
||||||
*
|
*
|
||||||
* Warning: Does not check whether index is consistent (not being used)
|
* Warning: Does not check whether index is consistent (not being used)
|
||||||
*/
|
*/
|
||||||
public synchronized boolean haveEncounteredHeader(IPath projectPath, IPath filePath) {
|
public synchronized boolean haveEncounteredHeader(IPath projectPath, IPath filePath, boolean add) {
|
||||||
SimpleLookupTable headerTable = indexStorage.getEncounteredHeaders();
|
SimpleLookupTable headerTable = indexStorage.getEncounteredHeaders();
|
||||||
|
|
||||||
// Path is already canonical per construction
|
// Path is already canonical per construction
|
||||||
|
@ -173,7 +170,9 @@ public class SourceIndexer extends AbstractCExtension implements ICDTIndexer {
|
||||||
if (headers.containsKey(filePath.toOSString()))
|
if (headers.containsKey(filePath.toOSString()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
headers.put(filePath.toOSString());
|
if (add) {
|
||||||
|
headers.put(filePath.toOSString());
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,7 @@ public class SourceIndexerRunner extends AbstractIndexer {
|
||||||
* @param path
|
* @param path
|
||||||
*/
|
*/
|
||||||
public boolean haveEncounteredHeader(IPath fullPath, Path path) {
|
public boolean haveEncounteredHeader(IPath fullPath, Path path) {
|
||||||
return indexer.haveEncounteredHeader(fullPath, path);
|
return indexer.haveEncounteredHeader(fullPath, path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class AddMarkerProblem extends Problem {
|
protected class AddMarkerProblem extends Problem {
|
||||||
|
|
Loading…
Add table
Reference in a new issue