mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-16 12:21:37 +00:00
Make base as template argument for optimization
This commit is contained in:
parent
2087e47300
commit
41b77e4f25
@ -145,10 +145,10 @@ void set_nice_name(const char *name) {
|
|||||||
prctl(PR_SET_NAME, name);
|
prctl(PR_SET_NAME, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T, int base>
|
||||||
static T parse_num(string_view s, int base) {
|
static T parse_num(string_view s) {
|
||||||
T acc = 0;
|
T val = 0;
|
||||||
for (char c: s) {
|
for (char c : s) {
|
||||||
if (isdigit(c)) {
|
if (isdigit(c)) {
|
||||||
c -= '0';
|
c -= '0';
|
||||||
} else if (base > 10 && isalpha(c)) {
|
} else if (base > 10 && isalpha(c)) {
|
||||||
@ -159,10 +159,10 @@ static T parse_num(string_view s, int base) {
|
|||||||
if (c >= base) {
|
if (c >= base) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
acc *= base;
|
val *= base;
|
||||||
acc += c;
|
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.
|
* Use our own implementation for faster conversion.
|
||||||
*/
|
*/
|
||||||
int parse_int(string_view s) {
|
int parse_int(string_view s) {
|
||||||
return parse_num<int>(s, 10);
|
return parse_num<int, 10>(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t parse_uint64_hex(string_view s) {
|
uint64_t parse_uint64_hex(string_view s) {
|
||||||
return parse_num<uint64_t>(s, 16);
|
return parse_num<uint64_t, 16>(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t binary_gcd(uint32_t u, uint32_t v) {
|
uint32_t binary_gcd(uint32_t u, uint32_t v) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user