[PATCH] D89922: SourceManager: Simplify by inlining what remains of ComputeLineNumbers, NFC
Duncan P. N. Exon Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 21 19:40:23 PDT 2020
dexonsmith updated this revision to Diff 299846.
dexonsmith added a comment.
Found a further simplification, removing a redundant call to `ContentCache::getBufferOrNone`.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89922/new/
https://reviews.llvm.org/D89922
Files:
clang/lib/Basic/SourceManager.cpp
Index: clang/lib/Basic/SourceManager.cpp
===================================================================
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1258,23 +1258,6 @@
#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
@@ -1340,12 +1323,15 @@
// 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;
@@ -1691,17 +1677,13 @@
// 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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89922.299846.patch
Type: text/x-patch
Size: 2628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201022/9c8998fb/attachment.bin>
More information about the cfe-commits
mailing list