mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Cache PDOMFiles in the fast indexer and reuse them when creating PDOMNames. Shaves 20% from Mozilla times.
This commit is contained in:
parent
ac1908c621
commit
34a2d013f9
10 changed files with 55 additions and 87 deletions
|
@ -252,7 +252,11 @@ public class PDOM extends PlatformObject
|
||||||
|
|
||||||
public int visit(IASTName name) {
|
public int visit(IASTName name) {
|
||||||
try {
|
try {
|
||||||
linkage.addName(name);
|
IASTFileLocation fileloc = name.getFileLocation();
|
||||||
|
if (fileloc != null) {
|
||||||
|
PDOMFile file = addFile(fileloc.getFileName());
|
||||||
|
linkage.addName(name, file);
|
||||||
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
|
|
|
@ -115,6 +115,15 @@ public class PDOMFile {
|
||||||
pdom.getDB().putInt(record + FIRST_NAME, namerec);
|
pdom.getDB().putInt(record + FIRST_NAME, namerec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addName(PDOMName name) throws CoreException {
|
||||||
|
PDOMName firstName = getFirstName();
|
||||||
|
if (firstName != null) {
|
||||||
|
name.setNextInFile(firstName);
|
||||||
|
firstName.setPrevInFile(name);
|
||||||
|
}
|
||||||
|
setFirstName(name);
|
||||||
|
}
|
||||||
|
|
||||||
public PDOMInclude getFirstInclude() throws CoreException {
|
public PDOMInclude getFirstInclude() throws CoreException {
|
||||||
int increc = pdom.getDB().getInt(record + FIRST_INCLUDE);
|
int increc = pdom.getDB().getInt(record + FIRST_INCLUDE);
|
||||||
return increc != 0 ? new PDOMInclude(pdom, increc) : null;
|
return increc != 0 ? new PDOMInclude(pdom, increc) : null;
|
||||||
|
|
|
@ -136,7 +136,7 @@ public abstract class PDOMLinkage extends PDOMNode {
|
||||||
getIndex().insert(child.getRecord(), child.getIndexComparator());
|
getIndex().insert(child.getRecord(), child.getIndexComparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract PDOMBinding addName(IASTName name) throws CoreException;
|
public abstract PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException;
|
||||||
|
|
||||||
public abstract PDOMBinding adaptBinding(IBinding binding) throws CoreException;
|
public abstract PDOMBinding adaptBinding(IBinding binding) throws CoreException;
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class PDOMName implements IASTName, IASTFileLocation {
|
||||||
private static final int IS_REFERENCE = 3;
|
private static final int IS_REFERENCE = 3;
|
||||||
|
|
||||||
|
|
||||||
public PDOMName(PDOM pdom, IASTName name, PDOMBinding binding) throws CoreException {
|
public PDOMName(PDOM pdom, IASTName name, PDOMFile file, PDOMBinding binding) throws CoreException {
|
||||||
this.pdom = pdom;
|
this.pdom = pdom;
|
||||||
Database db = pdom.getDB();
|
Database db = pdom.getDB();
|
||||||
record = db.malloc(RECORD_SIZE);
|
record = db.malloc(RECORD_SIZE);
|
||||||
|
@ -82,17 +82,11 @@ public class PDOMName implements IASTName, IASTFileLocation {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook us up the the liked name list from file
|
// Hook us up the the liked name list from file
|
||||||
IASTFileLocation fileloc = name.getFileLocation();
|
db.putInt(record + FILE_REC_OFFSET, file.getRecord());
|
||||||
String filename = fileloc.getFileName();
|
file.addName(this);
|
||||||
PDOMFile pdomFile = pdom.addFile(filename);
|
|
||||||
db.putInt(record + FILE_REC_OFFSET, pdomFile.getRecord());
|
|
||||||
PDOMName firstName = pdomFile.getFirstName();
|
|
||||||
if (firstName != null) {
|
|
||||||
db.putInt(record + FILE_NEXT_OFFSET, firstName.getRecord());
|
|
||||||
firstName.setPrevInFile(this);
|
|
||||||
}
|
|
||||||
pdomFile.setFirstName(this);
|
|
||||||
|
|
||||||
|
// Record our location in the file
|
||||||
|
IASTFileLocation fileloc = name.getFileLocation();
|
||||||
db.putInt(record + NODE_OFFSET_OFFSET, fileloc.getNodeOffset());
|
db.putInt(record + NODE_OFFSET_OFFSET, fileloc.getNodeOffset());
|
||||||
db.putInt(record + NODE_LENGTH_OFFSET, fileloc.getNodeLength());
|
db.putInt(record + NODE_LENGTH_OFFSET, fileloc.getNodeLength());
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMember;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMember;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMemberOwner;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMemberOwner;
|
||||||
|
@ -84,7 +85,7 @@ public class PDOMCLinkage extends PDOMLinkage {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMBinding addName(IASTName name) throws CoreException {
|
public PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException {
|
||||||
if (name == null || name.toCharArray().length == 0)
|
if (name == null || name.toCharArray().length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ public class PDOMCLinkage extends PDOMLinkage {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdomBinding != null)
|
if (pdomBinding != null)
|
||||||
new PDOMName(pdom, name, pdomBinding);
|
new PDOMName(pdom, name, file, pdomBinding);
|
||||||
|
|
||||||
return pdomBinding;
|
return pdomBinding;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespaceAlias;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMember;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMember;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMemberOwner;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMemberOwner;
|
||||||
|
@ -97,7 +98,7 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMBinding addName(IASTName name) throws CoreException {
|
public PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException {
|
||||||
if (name == null || name instanceof ICPPASTQualifiedName)
|
if (name == null || name instanceof ICPPASTQualifiedName)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
||||||
|
|
||||||
// Add in the name
|
// Add in the name
|
||||||
if (pdomBinding != null)
|
if (pdomBinding != null)
|
||||||
new PDOMName(pdom, name, pdomBinding);
|
new PDOMName(pdom, name, file, pdomBinding);
|
||||||
|
|
||||||
return pdomBinding;
|
return pdomBinding;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||||
|
@ -98,8 +99,8 @@ public class CtagsCName implements IASTName, IASTFileLocation {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToPDOM() throws CoreException {
|
public void addToPDOM(PDOMFile file) throws CoreException {
|
||||||
linkage.addName(this);
|
linkage.addName(this, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding getBinding() {
|
public IBinding getBinding() {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||||
|
@ -98,8 +99,8 @@ public class CtagsCPPName implements IASTName, IASTFileLocation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToPDOM() throws CoreException {
|
public void addToPDOM(PDOMFile file) throws CoreException {
|
||||||
linkage.addName(this);
|
linkage.addName(this, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding getBinding() {
|
public IBinding getBinding() {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
@ -137,13 +138,14 @@ public abstract class CtagsIndexerJob extends Job {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elementName != null && fileName != null) {
|
if (elementName != null && fileName != null) {
|
||||||
|
PDOMFile file = pdom.addFile(fileName);
|
||||||
String languageName = (String)fields.get("language"); //$NON-NLS-1$
|
String languageName = (String)fields.get("language"); //$NON-NLS-1$
|
||||||
if (languageName.equals("C++")) { //$NON-NLS-1$
|
if (languageName.equals("C++")) { //$NON-NLS-1$
|
||||||
PDOMLinkage linkage = pdom.getLinkage(new GPPLanguage());
|
PDOMLinkage linkage = pdom.getLinkage(new GPPLanguage());
|
||||||
new CtagsCPPName(linkage, fileName, lineNum, elementName, fields).addToPDOM();
|
new CtagsCPPName(linkage, fileName, lineNum, elementName, fields).addToPDOM(file);
|
||||||
} else {
|
} else {
|
||||||
PDOMLinkage linkage = pdom.getLinkage(new GCCLanguage());
|
PDOMLinkage linkage = pdom.getLinkage(new GCCLanguage());
|
||||||
new CtagsCName(linkage, fileName, lineNum, elementName, fields).addToPDOM();
|
new CtagsCName(linkage, fileName, lineNum, elementName, fields).addToPDOM(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
@ -35,6 +37,7 @@ import org.eclipse.core.runtime.jobs.Job;
|
||||||
*/
|
*/
|
||||||
public abstract class PDOMFastIndexerJob extends Job {
|
public abstract class PDOMFastIndexerJob extends Job {
|
||||||
|
|
||||||
|
protected final Map fileMap = new HashMap();
|
||||||
protected final PDOM pdom;
|
protected final PDOM pdom;
|
||||||
|
|
||||||
public PDOMFastIndexerJob(PDOM pdom) {
|
public PDOMFastIndexerJob(PDOM pdom) {
|
||||||
|
@ -56,6 +59,15 @@ public abstract class PDOMFastIndexerJob extends Job {
|
||||||
ILanguage.AST_USE_INDEX | ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
ILanguage.AST_USE_INDEX | ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected PDOMFile getCachedFile(String filename) throws CoreException {
|
||||||
|
PDOMFile file = (PDOMFile)fileMap.get(filename);
|
||||||
|
if (file == null) {
|
||||||
|
file = pdom.addFile(filename);
|
||||||
|
fileMap.put(filename, file);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException {
|
protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException {
|
||||||
ILanguage language = tu.getLanguage();
|
ILanguage language = tu.getLanguage();
|
||||||
if (language == null)
|
if (language == null)
|
||||||
|
@ -89,9 +101,9 @@ public abstract class PDOMFastIndexerJob extends Job {
|
||||||
? sourceLoc.getFileName()
|
? sourceLoc.getFileName()
|
||||||
: ast.getFilePath(); // command-line includes
|
: ast.getFilePath(); // command-line includes
|
||||||
|
|
||||||
PDOMFile sourceFile = pdom.addFile(sourcePath);
|
PDOMFile sourceFile = getCachedFile(sourcePath);
|
||||||
String destPath = include.getPath();
|
String destPath = include.getPath();
|
||||||
PDOMFile destFile = pdom.addFile(destPath);
|
PDOMFile destFile = getCachedFile(destPath);
|
||||||
sourceFile.addIncludeTo(destFile);
|
sourceFile.addIncludeTo(destFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,9 +120,8 @@ public abstract class PDOMFastIndexerJob extends Job {
|
||||||
if (skippedHeaders.contains(filename))
|
if (skippedHeaders.contains(filename))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PDOMFile sourceFile = pdom.getFile(filename);
|
PDOMFile sourceFile = getCachedFile(filename);
|
||||||
if (sourceFile != null) // not sure why this would be null
|
sourceFile.addMacro(macro);
|
||||||
sourceFile.addMacro(macro);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add in the names
|
// Add in the names
|
||||||
|
@ -122,7 +133,9 @@ public abstract class PDOMFastIndexerJob extends Job {
|
||||||
|
|
||||||
public int visit(IASTName name) {
|
public int visit(IASTName name) {
|
||||||
try {
|
try {
|
||||||
linkage.addName(name);
|
IASTFileLocation nameLoc = name.getFileLocation();
|
||||||
|
if (nameLoc != null)
|
||||||
|
linkage.addName(name, getCachedFile(nameLoc.getFileName()));
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
|
@ -138,62 +151,4 @@ public abstract class PDOMFastIndexerJob extends Job {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSymbols(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
|
||||||
final PDOMLinkage linkage = pdom.getLinkage(language);
|
|
||||||
if (linkage == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Add in the includes
|
|
||||||
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
|
|
||||||
for (int i = 0; i < includes.length; ++i) {
|
|
||||||
IASTPreprocessorIncludeStatement include = includes[i];
|
|
||||||
|
|
||||||
IASTFileLocation sourceLoc = include.getFileLocation();
|
|
||||||
String sourcePath
|
|
||||||
= sourceLoc != null
|
|
||||||
? sourceLoc.getFileName()
|
|
||||||
: ast.getFilePath(); // command-line includes
|
|
||||||
|
|
||||||
PDOMFile sourceFile = pdom.addFile(sourcePath);
|
|
||||||
String destPath = include.getPath();
|
|
||||||
PDOMFile destFile = pdom.addFile(destPath);
|
|
||||||
sourceFile.addIncludeTo(destFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add in the macros
|
|
||||||
IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions();
|
|
||||||
for (int i = 0; i < macros.length; ++i) {
|
|
||||||
IASTPreprocessorMacroDefinition macro = macros[i];
|
|
||||||
|
|
||||||
IASTFileLocation sourceLoc = macro.getFileLocation();
|
|
||||||
if (sourceLoc == null)
|
|
||||||
continue; // skip built-ins and command line macros
|
|
||||||
|
|
||||||
PDOMFile sourceFile = pdom.getFile(sourceLoc.getFileName());
|
|
||||||
if (sourceFile != null) // not sure why this would be null
|
|
||||||
sourceFile.addMacro(macro);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add in the names
|
|
||||||
ast.accept(new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitNames = true;
|
|
||||||
shouldVisitDeclarations = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int visit(IASTName name) {
|
|
||||||
try {
|
|
||||||
linkage.addName(name);
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
return PROCESS_ABORT;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});;
|
|
||||||
|
|
||||||
// Tell the world
|
|
||||||
pdom.fireChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue