From 41b77e4f255be2e8e4608b6519dbc7d7aeb4b3ac Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 3 Apr 2023 18:28:41 -0700 Subject: [PATCH] Make base as template argument for optimization --- native/src/base/misc.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/native/src/base/misc.cpp b/native/src/base/misc.cpp index a4c692ec7..cdd355e4a 100644 --- a/native/src/base/misc.cpp +++ b/native/src/base/misc.cpp @@ -145,10 +145,10 @@ void set_nice_name(const char *name) { prctl(PR_SET_NAME, name); } -template -static T parse_num(string_view s, int base) { - T acc = 0; - for (char c: s) { +template +static T parse_num(string_view s) { + T val = 0; + for (char c : s) { if (isdigit(c)) { c -= '0'; } else if (base > 10 && isalpha(c)) { @@ -159,10 +159,10 @@ static T parse_num(string_view s, int base) { if (c >= base) { return -1; } - acc *= base; - acc += c; + val *= base; + val += c; } - return acc; + return val; } /* @@ -170,11 +170,11 @@ static T parse_num(string_view s, int base) { * Use our own implementation for faster conversion. */ int parse_int(string_view s) { - return parse_num(s, 10); + return parse_num(s); } uint64_t parse_uint64_hex(string_view s) { - return parse_num(s, 16); + return parse_num(s); } uint32_t binary_gcd(uint32_t u, uint32_t v) {