From 4b67bb14601c2d9a76d034c2336a242f51ee717b Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Thu, 16 Jan 2020 11:27:51 -0800 Subject: [PATCH] src: reduce large pages code duplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Declaring and initializing a `struct text_region` is common to all three implementations of the large pages mapping code. Let's make it unconditional. PR-URL: https://github.com/nodejs/node/pull/31385 Reviewed-By: Ben Noordhuis Reviewed-By: Rich Trott Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Jiawen Geng Reviewed-By: David Carlier Reviewed-By: JungMinu - Minwoo Jung Reviewed-By: Richard Lau Reviewed-By: Gus Caplan --- src/large_pages/node_large_page.cc | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/large_pages/node_large_page.cc b/src/large_pages/node_large_page.cc index 5a4d302361ac19..f636c9f3142376 100644 --- a/src/large_pages/node_large_page.cc +++ b/src/large_pages/node_large_page.cc @@ -100,6 +100,8 @@ inline uintptr_t hugepage_align_down(uintptr_t addr) { // This is also handling the case where the first line is not the binary. static struct text_region FindNodeTextRegion() { + struct text_region nregion; + nregion.found_text_region = false; #if defined(__linux__) std::ifstream ifs; std::string map_line; @@ -107,9 +109,6 @@ static struct text_region FindNodeTextRegion() { std::string dev; char dash; uintptr_t start, end, offset, inode; - struct text_region nregion; - - nregion.found_text_region = false; ifs.open("/proc/self/maps"); if (!ifs) { @@ -161,9 +160,6 @@ static struct text_region FindNodeTextRegion() { ifs.close(); #elif defined(__FreeBSD__) - struct text_region nregion; - nregion.found_text_region = false; - std::string exename; { char selfexe[PATH_MAX]; @@ -220,8 +216,6 @@ static struct text_region FindNodeTextRegion() { start += cursz; } #elif defined(__APPLE__) - struct text_region nregion; - nregion.found_text_region = false; struct vm_region_submap_info_64 map; mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT_64; vm_address_t addr = 0UL;