mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 07:55:24 +02:00
Bug #120361: IndexEncoderUtil.nodeInVisitedExternalHeader() performance
This commit is contained in:
parent
d78c26534a
commit
681c59c039
2 changed files with 31 additions and 10 deletions
|
@ -183,10 +183,29 @@ public class DOMSourceIndexer extends AbstractCExtension implements ICDTIndexer
|
||||||
headers.put(filePath.toOSString());
|
headers.put(filePath.toOSString());
|
||||||
added++;
|
added++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lighter version of the same method
|
||||||
|
public synchronized boolean haveEncounteredHeader(IPath projectPath, String filePath) {
|
||||||
|
SimpleLookupTable headerTable = indexStorage.getEncounteredHeaders();
|
||||||
|
|
||||||
|
// Path is already canonical per construction
|
||||||
|
ObjectSet headers = (ObjectSet) headerTable.get(projectPath);
|
||||||
|
if (headers == null) {
|
||||||
|
//First time for the project, must create a new ObjectSet
|
||||||
|
headers = new ObjectSet(4);
|
||||||
|
headerTable.put(projectPath, headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headers.containsKey(filePath)) {
|
||||||
|
trimed++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,7 +15,6 @@ 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.internal.core.index.cindexstorage.IndexedFileEntry;
|
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
|
||||||
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 {
|
||||||
|
@ -73,26 +72,29 @@ public class IndexEncoderUtil {
|
||||||
public static IASTFileLocation getFileLocation(IASTNode node) {
|
public static IASTFileLocation getFileLocation(IASTNode node) {
|
||||||
return node.getFileLocation();
|
return node.getFileLocation();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* This method is never called
|
||||||
|
*
|
||||||
public static boolean nodeInExternalHeader(IASTNode node) {
|
public static boolean nodeInExternalHeader(IASTNode node) {
|
||||||
String fileName = node.getContainingFilename();
|
String fileName = node.getContainingFilename();
|
||||||
return (CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName)) == null)
|
return (CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName)) == null)
|
||||||
? true : false;
|
? true : false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
static private boolean visitedExternalHeader = false;
|
static private boolean visitedExternalHeader = false;
|
||||||
static private String lastVisitedFile = null;
|
static private String lastVisitedFile = null;
|
||||||
|
static private String wspLocation = CCorePlugin.getWorkspace().getRoot().getLocation().toOSString();
|
||||||
|
|
||||||
public static boolean nodeInVisitedExternalHeader(IASTNode node, DOMSourceIndexer indexer) {
|
public static boolean nodeInVisitedExternalHeader(IASTNode node, DOMSourceIndexer indexer) {
|
||||||
String fileName = node.getContainingFilename();
|
String fileName = node.getContainingFilename();
|
||||||
if (fileName.equals(lastVisitedFile)) {
|
|
||||||
|
// if file is the same as before, return previous result.
|
||||||
|
if (fileName.equals(lastVisitedFile)) {
|
||||||
return visitedExternalHeader;
|
return visitedExternalHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastVisitedFile = fileName;
|
lastVisitedFile = fileName;
|
||||||
IPath filePath = new Path(fileName);
|
// If file is external, check whether it's encountered
|
||||||
IPath projectPath = indexer.getProject().getFullPath();
|
visitedExternalHeader = (!fileName.startsWith(wspLocation)) && indexer.haveEncounteredHeader(indexer.getProject().getFullPath(), fileName);
|
||||||
visitedExternalHeader = (CCorePlugin.getWorkspace().getRoot().getFileForLocation(filePath) == null) &&
|
|
||||||
indexer.haveEncounteredHeader(projectPath, filePath, false);
|
|
||||||
return visitedExternalHeader;
|
return visitedExternalHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue