Skip to content

Commit

Permalink
Fix Windows file memory mapping to work with large files (>2GB).
Browse files Browse the repository at this point in the history
Fix thanks to Steve Booth.

Also, remove a gratuitous and inefficient string copy of the mapped file.
  • Loading branch information
mmp committed Jul 13, 2018
1 parent 9f717d8 commit f80c3cf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ std::unique_ptr<Tokenizer> Tokenizer::CreateFromFile(
return errorReportLambda();
}

size_t len = GetFileSize(fileHandle, 0);
LARGE_INTEGER liLen;
if (!GetFileSizeEx(fileHandle, &liLen)) {
return errorReportLambda();
}
size_t len = liLen.QuadPart;

HANDLE mapping = CreateFileMapping(fileHandle, 0, PAGE_READONLY, 0, 0, 0);
CloseHandle(fileHandle);
Expand All @@ -172,8 +176,6 @@ std::unique_ptr<Tokenizer> Tokenizer::CreateFromFile(
return errorReportLambda();
}

std::string str(static_cast<const char *>(ptr), len);

return std::unique_ptr<Tokenizer>(
new Tokenizer(ptr, len, filename, std::move(errorCallback)));
#else
Expand Down

0 comments on commit f80c3cf

Please sign in to comment.