From: Yedidya Feldblum Date: Fri, 21 Jul 2017 02:29:14 +0000 (-0700) Subject: Parse suffixes without switch-fallthrough in huge-pages X-Git-Tag: v2017.07.24.00~10 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=af8f1710d90ece63b05cda944138189933bd3436;p=folly.git 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 --- 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; } /**