aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-10-21 22:31:15 -0400
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-10-23 14:56:41 -0400
commitcf52a85ddc9be165daca3d32521747c898f4ffd1 (patch)
treeff82726b5826211b4d97216e3a00c308c1645ac7 /clang/lib/Basic/SourceManager.cpp
parentb7926ce6d7a83cdf70c68d82bc3389c04009b841 (diff)
downloadllvm-cf52a85ddc9be165daca3d32521747c898f4ffd1.zip
llvm-cf52a85ddc9be165daca3d32521747c898f4ffd1.tar.gz
llvm-cf52a85ddc9be165daca3d32521747c898f4ffd1.tar.bz2
SourceManager: Simplify by inlining what remains of ComputeLineNumbers, NFC
Use `LineOffsetMapping:get` directly and remove/inline the helper `ComputeLineNumbers`, simplifying the callers. Differential Revision: https://reviews.llvm.org/D89922
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp38
1 files changed, 10 insertions, 28 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index f8607b0d..1feb8c7 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1260,23 +1260,6 @@ unsigned SourceManager::getPresumedColumnNumber(SourceLocation Loc,
#include <emmintrin.h>
#endif
-static LLVM_ATTRIBUTE_NOINLINE void
-ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI,
- llvm::BumpPtrAllocator &Alloc,
- const SourceManager &SM, bool &Invalid);
-static void ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI,
- llvm::BumpPtrAllocator &Alloc,
- const SourceManager &SM, bool &Invalid) {
- // Note that calling 'getBuffer()' may lazily page in the file.
- llvm::Optional<llvm::MemoryBufferRef> Buffer =
- FI.getBufferOrNone(Diag, SM.getFileManager(), SourceLocation());
- Invalid = !Buffer;
- if (Invalid)
- return;
-
- FI.SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc);
-}
-
LineOffsetMapping LineOffsetMapping::get(llvm::MemoryBufferRef Buffer,
llvm::BumpPtrAllocator &Alloc) {
// Find the file offsets of all of the *physical* source lines. This does
@@ -1342,12 +1325,15 @@ unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,
// If this is the first use of line information for this buffer, compute the
/// SourceLineCache for it on demand.
if (!Content->SourceLineCache) {
- bool MyInvalid = false;
- ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid);
+ llvm::Optional<llvm::MemoryBufferRef> Buffer =
+ Content->getBufferOrNone(Diag, getFileManager(), SourceLocation());
if (Invalid)
- *Invalid = MyInvalid;
- if (MyInvalid)
+ *Invalid = !Buffer;
+ if (!Buffer)
return 1;
+
+ Content->SourceLineCache =
+ LineOffsetMapping::get(*Buffer, ContentCacheAlloc);
} else if (Invalid)
*Invalid = false;
@@ -1689,17 +1675,13 @@ SourceLocation SourceManager::translateLineCol(FileID FID,
// If this is the first use of line information for this buffer, compute the
// SourceLineCache for it on demand.
- if (!Content->SourceLineCache) {
- bool MyInvalid = false;
- ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid);
- if (MyInvalid)
- return SourceLocation();
- }
-
llvm::Optional<llvm::MemoryBufferRef> Buffer =
Content->getBufferOrNone(Diag, getFileManager());
if (!Buffer)
return SourceLocation();
+ if (!Content->SourceLineCache)
+ Content->SourceLineCache =
+ LineOffsetMapping::get(*Buffer, ContentCacheAlloc);
if (Line > Content->SourceLineCache.size()) {
unsigned Size = Buffer->getBufferSize();