Commit af8f1710 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

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
parent 060471a0
......@@ -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<size_t>(numStr);
auto const size = to<size_t>(numStr);
auto const mult = [c] {
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;
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;
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment