From 5b22093f47a315afb44afe43cbdc7cd15b993f86 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 9 Mar 2017 20:48:50 -0800 Subject: [PATCH] Bug 513345 - A lot of time during indexing is spent inside CompositeValue.create Added precalculation of initial values of non-field variables. Change-Id: Ie6c0690d90d5725e812d10afa15c4a11ba92f647 --- .../cdt/internal/core/pdom/PDOMWriter.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java index 7ca4de3ea3e..a68ecd1d76b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java @@ -45,10 +45,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexInclude; @@ -358,7 +360,7 @@ public abstract class PDOMWriter implements IPDOMASTProcessor { private void resolveNames(Data data, IProgressMonitor monitor) { long start= System.currentTimeMillis(); - List variables = new ArrayList<>(); + Set variables = new HashSet<>(); SubMonitor progress = SubMonitor.convert(monitor, data.fSelectedFiles.length); for (FileInAST file : data.fSelectedFiles) { Symbols symbols= data.fSymbolMap.get(file.includeStatement); @@ -419,14 +421,11 @@ public abstract class PDOMWriter implements IPDOMASTProcessor { } } - // Precalculate types and initial values of all fields to avoid doing it later when writing + // Precalculate types and initial values of all indexed variables to avoid doing it later when writing // to the index. for (ICPPInternalDeclaredVariable variable : variables) { variable.allDeclarationsDefinitionsAdded(); - // TODO(sprigogin): It would be beneficial to precalculate types and initial values of all - // indexed variables not just fields. It should be done carefully to avoid - // unnecesssary overhead of doing it for variables that are not being indexed. - if (variable instanceof ICPPField) { + if (isVariableIndexed(variable)) { // Type and initial value will be cached by the variable. variable.getType(); variable.getInitialValue(); @@ -436,6 +435,15 @@ public abstract class PDOMWriter implements IPDOMASTProcessor { fStatistics.fResolutionTime += System.currentTimeMillis() - start; } + private boolean isVariableIndexed(ICPPVariable variable) { + if (variable instanceof ICPPField) + return true; + IBinding owner = variable.getOwner(); + if (owner == null || owner instanceof IASTTranslationUnit || owner instanceof ICPPNamespace) + return true; + return owner instanceof ICPPFunction && ((ICPPFunction) owner).isConstexpr(); + } + @Override public int process(final IASTTranslationUnit ast, final IIndexSymbols symbols) throws CoreException { if (!(symbols instanceof Data)) {