From af8f1710d90ece63b05cda944138189933bd3436 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Thu, 20 Jul 2017 19:29:14 -0700 Subject: [PATCH] Parse suffixes without switch-fallthrough in huge-pages Summary: [Folly] Parse suffixes without switch-fallthrough in huge-pages. It is clever, but weird. We can use an immediately-executed lambda expression to make it convenient. Reviewed By: Orvid Differential Revision: D5467585 fbshipit-source-id: 02ddb97641db97e38e3f40388ecc522eccd436cb --- folly/experimental/io/HugePages.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/folly/experimental/io/HugePages.cpp b/folly/experimental/io/HugePages.cpp index fbbd7708..d59d5874 100644 --- a/folly/experimental/io/HugePages.cpp +++ b/folly/experimental/io/HugePages.cpp @@ -98,14 +98,22 @@ size_t parsePageSizeValue(StringPiece value) { c = char(tolower(value[size_t(match.position(2))])); } StringPiece numStr(value.data() + match.position(1), size_t(match.length(1))); - size_t size = to(numStr); - switch (c) { - case 't': size *= 1024; FOLLY_FALLTHROUGH; - case 'g': size *= 1024; FOLLY_FALLTHROUGH; - case 'm': size *= 1024; FOLLY_FALLTHROUGH; - case 'k': size *= 1024; - } - return size; + auto const size = to(numStr); + auto const mult = [c] { + switch (c) { + case 't': + return 1ull << 40; + case 'g': + return 1ull << 30; + case 'm': + return 1ull << 20; + case 'k': + return 1ull << 10; + default: + return 1ull << 0; + } + }(); + return size * mult; } /** -- 2.34.1