Skip to content

Commit d793bbd

Browse files
committed
[clang][modules] Cache deserialized SLocEntry offsets
1 parent 4edf9d8 commit d793bbd

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clang/include/clang/Serialization/ModuleFile.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,12 @@ class ModuleFile {
288288
/// for the entry is SLocEntryOffsetsBase + SLocEntryOffsets[i].
289289
uint64_t SLocEntryOffsetsBase = 0;
290290

291-
/// Offsets for all of the source location entries in the
292-
/// AST file.
291+
/// Stream bit offsets for all of the source location entries in the AST file.
293292
const uint32_t *SLocEntryOffsets = nullptr;
294293

294+
/// SLocEntry offsets that have been loaded from the AST file.
295+
std::vector<SourceLocation::UIntTy> SLocEntryOffsetLoaded;
296+
295297
/// SLocEntries that we're going to preload.
296298
SmallVector<uint64_t, 4> PreloadSLocEntries;
297299

clang/lib/Serialization/ASTReader.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,9 +1497,12 @@ int ASTReader::getSLocEntryID(SourceLocation::UIntTy SLocOffset) {
14971497

14981498
auto It = llvm::upper_bound(Indices, SLocOffset,
14991499
[&](SourceLocation::UIntTy Offset, unsigned Index) {
1500-
auto EntryOffset = readSLocOffset(F, Index);
1501-
assert(EntryOffset && "Corrupted AST file");
1502-
return Offset < *EntryOffset;
1500+
if (F->SLocEntryOffsetLoaded[Index] == -1U) {
1501+
auto MaybeEntryOffset = readSLocOffset(F, Index);
1502+
assert(MaybeEntryOffset && "Corrupted AST file");
1503+
F->SLocEntryOffsetLoaded[Index] = *MaybeEntryOffset;
1504+
}
1505+
return Offset < F->SLocEntryOffsetLoaded[Index];
15031506
});
15041507
// The iterator points to the first entry with start offset greater than the
15051508
// offset of interest. The previous entry must contain the offset of interest.
@@ -3606,6 +3609,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
36063609
return llvm::createStringError(std::errc::invalid_argument,
36073610
"ran out of source locations");
36083611
}
3612+
F.SLocEntryOffsetLoaded.resize(F.LocalNumSLocEntries, -1U);
36093613
// Make our entry in the range map. BaseID is negative and growing, so
36103614
// we invert it. Because we invert it, though, we need the other end of
36113615
// the range.

0 commit comments

Comments
 (0)