Commit f9899c2d authored by Marco Bubke's avatar Marco Bubke Committed by Nikolai Kosjar
Browse files

Clang: Little speedup for code completion



...by ensuring that the precompiled preamble is created.

Change-Id: I80784b6a79c40a7e452530e8288783f33f881efc
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent dbe4e322
......@@ -163,10 +163,6 @@ void TranslationUnit::removeOutdatedTranslationUnit() const
void TranslationUnit::createTranslationUnitIfNeeded() const
{
const auto options = CXTranslationUnit_CacheCompletionResults
| CXTranslationUnit_PrecompiledPreamble
| CXTranslationUnit_SkipFunctionBodies;
if (!d->translationUnit) {
d->translationUnit = CXTranslationUnit();
CXErrorCode errorCode = clang_parseTranslationUnit2(index(),
......@@ -175,11 +171,15 @@ void TranslationUnit::createTranslationUnitIfNeeded() const
d->projectPart.argumentCount(),
d->unsavedFiles.cxUnsavedFiles(),
d->unsavedFiles.count(),
options,
defaultOptions(),
&d->translationUnit);
checkTranslationUnitErrorCode(errorCode);
// We need to reparse to create the precompiled preamble, which will speed up further calls,
// e.g. clang_codeCompleteAt() dramatically.
reparseTranslationUnit();
updateLastChangeTimePoint();
}
}
......@@ -192,6 +192,21 @@ void TranslationUnit::checkTranslationUnitErrorCode(CXErrorCode errorCode) const
}
}
void TranslationUnit::reparseTranslationUnit() const
{
clang_reparseTranslationUnit(d->translationUnit,
d->unsavedFiles.count(),
d->unsavedFiles.cxUnsavedFiles(),
clang_defaultReparseOptions(d->translationUnit));
}
int TranslationUnit::defaultOptions()
{
return CXTranslationUnit_CacheCompletionResults
| CXTranslationUnit_PrecompiledPreamble
| CXTranslationUnit_SkipFunctionBodies;
}
uint TranslationUnit::unsavedFilesCount() const
{
return d->unsavedFiles.count();
......
......@@ -91,6 +91,8 @@ private:
void removeOutdatedTranslationUnit() const;
void createTranslationUnitIfNeeded() const;
void checkTranslationUnitErrorCode(CXErrorCode errorCode) const;
void reparseTranslationUnit() const;
static int defaultOptions();
private:
mutable std::shared_ptr<TranslationUnitData> d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment