Shortcut JSBigFileString in when no offset is used

Reviewed By: mhorowitz

Differential Revision: D5227225

fbshipit-source-id: a50688c8b873bf08ea10fafaa143df130f59dfaa
This commit is contained in:
Pieter De Baets 2017-09-05 03:07:16 -07:00 committed by Facebook Github Bot
parent eb6ba0b041
commit 8497ec297c

View File

@ -112,20 +112,25 @@ public:
: m_fd {-1}
, m_data {nullptr}
{
folly::checkUnixError(
m_fd = dup(fd),
"Could not duplicate file descriptor");
folly::checkUnixError(m_fd = dup(fd),
"Could not duplicate file descriptor");
// Offsets given to mmap must be page aligend. We abstract away that
// restriction by sending a page aligned offset to mmap, and keeping track
// of the offset within the page that we must alter the mmap pointer by to
// get the final desired offset.
auto ps = getpagesize();
auto d = lldiv(offset, ps);
if (offset != 0) {
const static auto ps = getpagesize();
auto d = lldiv(offset, ps);
m_mapOff = d.quot;
m_pageOff = d.rem;
m_size = size + m_pageOff;
m_mapOff = d.quot;
m_pageOff = d.rem;
m_size = size + m_pageOff;
} else {
m_mapOff = 0;
m_pageOff = 0;
m_size = size;
}
}
~JSBigFileString() {