From 8497ec297cf0f96b450952a64dc4fb4b10efba93 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 5 Sep 2017 03:07:16 -0700 Subject: [PATCH] Shortcut JSBigFileString in when no offset is used Reviewed By: mhorowitz Differential Revision: D5227225 fbshipit-source-id: a50688c8b873bf08ea10fafaa143df130f59dfaa --- ReactCommon/cxxreact/JSBigString.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ReactCommon/cxxreact/JSBigString.h b/ReactCommon/cxxreact/JSBigString.h index 33a92d117..0a16e551d 100644 --- a/ReactCommon/cxxreact/JSBigString.h +++ b/ReactCommon/cxxreact/JSBigString.h @@ -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() {