mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[IDE] Pass a SourceRange instead of a CharSourceRange in SemaAnnotator::passReference
Most `SemaAnnotator`s don’t actually care about the char source range. Instead, they only care about the start location of the reference, which is also included in `SourceRange`. Computing a `CharSourceRange` from a `SourceRange` is kind of expensive because it needs to start a new lexer. To avoid this overhead, pass `SourceRange` to `SemaAnnotator::passReference` and related functions and let the clients compute the `CharSourceRange` when needed. This reduces the overhead of index-while-building by about 10%.
This commit is contained in:
@@ -1203,21 +1203,24 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool visitDeclReference(ValueDecl *D, CharSourceRange Range,
|
||||
TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef, Type Ty,
|
||||
bool visitDeclReference(ValueDecl *D, SourceRange Range, TypeDecl *CtorTyRef,
|
||||
ExtensionDecl *ExtTyRef, Type Ty,
|
||||
ReferenceMetaData Data) override {
|
||||
if (Data.isImplicit || !Range.isValid())
|
||||
return true;
|
||||
// Ignore things that don't come from this buffer.
|
||||
if (!SM.getRangeForBuffer(BufferID).contains(Range.getStart()))
|
||||
if (!SM.getRangeForBuffer(BufferID).contains(Range.Start))
|
||||
return true;
|
||||
|
||||
unsigned StartOffset = getOffset(Range.getStart());
|
||||
References.emplace_back(D, StartOffset, Range.getByteLength(), Ty);
|
||||
CharSourceRange CharRange = Lexer::getCharSourceRangeFromSourceRange(
|
||||
D->getASTContext().SourceMgr, Range);
|
||||
|
||||
unsigned StartOffset = getOffset(CharRange.getStart());
|
||||
References.emplace_back(D, StartOffset, CharRange.getByteLength(), Ty);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool visitSubscriptReference(ValueDecl *D, CharSourceRange Range,
|
||||
bool visitSubscriptReference(ValueDecl *D, SourceRange Range,
|
||||
ReferenceMetaData Data,
|
||||
bool IsOpenBracket) override {
|
||||
// Treat both open and close brackets equally
|
||||
|
||||
Reference in New Issue
Block a user