aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/mod-file.cpp
diff options
context:
space:
mode:
authorDavid Truby <david.truby@arm.com>2020-02-27 13:42:56 +0000
committerDavid Truby <david.truby@arm.com>2020-03-24 13:35:01 +0000
commit13ea73e42db3685091b1028991cf9f68d07fd7ac (patch)
treeacc4dcaa936b32df4e3a29b5a6f0f9aa3a22001d /flang/lib/Semantics/mod-file.cpp
parent901198441ffa6dea0953bcef4bc5c238708b384a (diff)
downloadllvm-13ea73e42db3685091b1028991cf9f68d07fd7ac.zip
llvm-13ea73e42db3685091b1028991cf9f68d07fd7ac.tar.gz
llvm-13ea73e42db3685091b1028991cf9f68d07fd7ac.tar.bz2
[flang] Replace manual mmap with llvm::MemoryBuffer
The previous code had handling for cases when too many file descriptors may be opened; this is not necessary with MemoryBuffer as the file descriptors are closed after the mapping occurs. MemoryBuffer also internally handles the case where a file is small and therefore an mmap is bad for performance; such files are simply copied to memory after being opened. Many places elsewhere in the code assume that the buffer is not empty, and the old file opening code handles this by replacing an empty file with a buffer containing a single newline. That behavior is now kept in the new MemoryBuffer based code. Original-commit: flang-compiler/f18@d34df8435127d847867e2c0bb157def9f20f4202 Reviewed-on: https://github.com/flang-compiler/f18/pull/1032
Diffstat (limited to 'flang/lib/Semantics/mod-file.cpp')
-rw-r--r--flang/lib/Semantics/mod-file.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index bbf62f9..5c45732 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -728,8 +728,8 @@ static std::string CheckSum(const std::string_view &contents) {
return result;
}
-static bool VerifyHeader(const char *content, std::size_t len) {
- std::string_view sv{content, len};
+static bool VerifyHeader(llvm::ArrayRef<char> content) {
+ std::string_view sv{content.data(), content.size()};
if (sv.substr(0, ModHeader::magicLen) != ModHeader::magic) {
return false;
}
@@ -767,7 +767,7 @@ Scope *ModFileReader::Read(const SourceName &name, Scope *ancestor) {
return nullptr;
}
CHECK(sourceFile);
- if (!VerifyHeader(sourceFile->content(), sourceFile->bytes())) {
+ if (!VerifyHeader(sourceFile->content())) {
Say(name, ancestorName, "File has invalid checksum: %s"_en_US,
sourceFile->path());
return nullptr;