forked from OSchip/llvm-project
[clangd] Make IncludeInserter less slow. NFC
llvm-svn: 343223
This commit is contained in:
parent
95a816b34a
commit
fd9f426049
|
@ -126,6 +126,12 @@ IncludeStructure::includeDepth(llvm::StringRef Root) const {
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IncludeInserter::addExisting(const Inclusion &Inc) {
|
||||||
|
IncludedHeaders.insert(Inc.Written);
|
||||||
|
if (!Inc.Resolved.empty())
|
||||||
|
IncludedHeaders.insert(Inc.Resolved);
|
||||||
|
}
|
||||||
|
|
||||||
/// FIXME(ioeric): we might not want to insert an absolute include path if the
|
/// FIXME(ioeric): we might not want to insert an absolute include path if the
|
||||||
/// path is not shortened.
|
/// path is not shortened.
|
||||||
bool IncludeInserter::shouldInsertInclude(
|
bool IncludeInserter::shouldInsertInclude(
|
||||||
|
@ -133,12 +139,6 @@ bool IncludeInserter::shouldInsertInclude(
|
||||||
assert(DeclaringHeader.valid() && InsertedHeader.valid());
|
assert(DeclaringHeader.valid() && InsertedHeader.valid());
|
||||||
if (FileName == DeclaringHeader.File || FileName == InsertedHeader.File)
|
if (FileName == DeclaringHeader.File || FileName == InsertedHeader.File)
|
||||||
return false;
|
return false;
|
||||||
llvm::StringSet<> IncludedHeaders;
|
|
||||||
for (const auto &Inc : Inclusions) {
|
|
||||||
IncludedHeaders.insert(Inc.Written);
|
|
||||||
if (!Inc.Resolved.empty())
|
|
||||||
IncludedHeaders.insert(Inc.Resolved);
|
|
||||||
}
|
|
||||||
auto Included = [&](llvm::StringRef Header) {
|
auto Included = [&](llvm::StringRef Header) {
|
||||||
return IncludedHeaders.find(Header) != IncludedHeaders.end();
|
return IncludedHeaders.find(Header) != IncludedHeaders.end();
|
||||||
};
|
};
|
||||||
|
|
|
@ -97,7 +97,7 @@ public:
|
||||||
HeaderSearchInfo(HeaderSearchInfo),
|
HeaderSearchInfo(HeaderSearchInfo),
|
||||||
Inserter(FileName, Code, Style.IncludeStyle) {}
|
Inserter(FileName, Code, Style.IncludeStyle) {}
|
||||||
|
|
||||||
void addExisting(Inclusion Inc) { Inclusions.push_back(std::move(Inc)); }
|
void addExisting(const Inclusion &Inc);
|
||||||
|
|
||||||
/// Checks whether to add an #include of the header into \p File.
|
/// Checks whether to add an #include of the header into \p File.
|
||||||
/// An #include will not be added if:
|
/// An #include will not be added if:
|
||||||
|
@ -134,8 +134,8 @@ private:
|
||||||
StringRef Code;
|
StringRef Code;
|
||||||
StringRef BuildDir;
|
StringRef BuildDir;
|
||||||
HeaderSearch &HeaderSearchInfo;
|
HeaderSearch &HeaderSearchInfo;
|
||||||
std::vector<Inclusion> Inclusions;
|
llvm::StringSet<> IncludedHeaders; // Both written and resolved.
|
||||||
tooling::HeaderIncludes Inserter; // Computers insertion replacement.
|
tooling::HeaderIncludes Inserter; // Computers insertion replacement.
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace clangd
|
} // namespace clangd
|
||||||
|
|
Loading…
Reference in New Issue