From 3b7fdaa534a8710f62cba2575b755705917ca70b Mon Sep 17 00:00:00 2001 From: Mikhail Korotov Date: Tue, 21 Jan 2020 23:00:43 +0300 Subject: [PATCH] changes made --- dbms/src/IO/ReadHelpers.h | 80 +++++-------------- .../01039_test_setting_parse.reference | 2 + .../0_stateless/01039_test_setting_parse.sql | 4 + 3 files changed, 28 insertions(+), 58 deletions(-) diff --git a/dbms/src/IO/ReadHelpers.h b/dbms/src/IO/ReadHelpers.h index a12c7d5c55d..02ce6909f35 100644 --- a/dbms/src/IO/ReadHelpers.h +++ b/dbms/src/IO/ReadHelpers.h @@ -966,76 +966,40 @@ readTextWithSuffix(T & x, ReadBuffer & buf) readIntText(x, buf); if (buf.eof()) return; + + auto F = [&buf, &x] (long long base, int power_of_two) mutable + { + ++buf.position(); + if (buf.eof()) + { + x *= base; + } + else if (*buf.position() == 'i') + { + x = (x << power_of_two); + ++buf.position(); + } + return; + }; + switch (*buf.position()) { - case 'k': - ++buf.position(); - if (buf.eof()) - { - x *= 1000; - return; - } - else if (*buf.position() == 'i') - { - x = (x << 10); - } - else - { - return; - } + case 'k': [[fallthrough]]; + case 'K': + F(1000, 10); break; case 'M': - ++buf.position(); - if (buf.eof()) - { - x *= 1000000; /// 1e+6 - return; - } - else if (*buf.position() == 'i') - { - x = (x << 20); - } - else - { - return; - } + F(1000000, 20); break; case 'G': - ++buf.position(); - if (buf.eof()) - { - x *= 1000000000; /// 1e+9 - return; - } - else if (*buf.position() == 'i') - { - x = (x << 30); - } - else - { - return; - } + F(1000000000, 30); break; case 'T': - ++buf.position(); - if (buf.eof()) - { - x *= 1000000000000; /// 1e+12 - return; - } - else if (*buf.position() == 'i') - { - x = (x << 40); - } - else - { - return; - } + F(1000000000000ULL, 40); break; default: return; } - ++buf.position(); return; } diff --git a/dbms/tests/queries/0_stateless/01039_test_setting_parse.reference b/dbms/tests/queries/0_stateless/01039_test_setting_parse.reference index 9fbf4df175f..49233946390 100644 --- a/dbms/tests/queries/0_stateless/01039_test_setting_parse.reference +++ b/dbms/tests/queries/0_stateless/01039_test_setting_parse.reference @@ -2,6 +2,8 @@ 3221225472 1567000 125952 +1567000 +125952 12000000 32505856 1000000000000 diff --git a/dbms/tests/queries/0_stateless/01039_test_setting_parse.sql b/dbms/tests/queries/0_stateless/01039_test_setting_parse.sql index a5c1b46e033..6a4eadf6a40 100644 --- a/dbms/tests/queries/0_stateless/01039_test_setting_parse.sql +++ b/dbms/tests/queries/0_stateless/01039_test_setting_parse.sql @@ -6,6 +6,10 @@ SET max_memory_usage = '1567k'; SELECT value FROM system.settings WHERE name = 'max_memory_usage'; SET max_memory_usage = '123ki'; SELECT value FROM system.settings WHERE name = 'max_memory_usage'; +SET max_memory_usage = '1567K'; +SELECT value FROM system.settings WHERE name = 'max_memory_usage'; +SET max_memory_usage = '123Ki'; +SELECT value FROM system.settings WHERE name = 'max_memory_usage'; SET max_memory_usage = '12M'; SELECT value FROM system.settings WHERE name = 'max_memory_usage'; SET max_memory_usage = '31Mi';