0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-17 08:38:42 +00:00

Lib: Optimized printing of numbers

One simple trick makes printing of numbers ~4x faster.
This commit is contained in:
Ondrej Zajicek 2024-11-08 18:54:13 +01:00
parent 5c6572c422
commit 49be4a0329

View File

@ -73,10 +73,25 @@ static char * number(char * str, u64 num, uint base, int size, int precision,
i = 0;
if (num == 0)
tmp[i++]='0';
else while (num != 0) {
uint res = num % base;
num = num / base;
tmp[i++] = digits[res];
else if (base == 10) {
/* Separate cases to have fixed divisors */
while (num != 0) {
uint res = num % 10;
num = num / 10;
tmp[i++] = digits[res];
}
} else if (base == 16) {
while (num != 0) {
uint res = num % 16;
num = num / 16;
tmp[i++] = digits[res];
}
} else {
while (num != 0) {
uint res = num % base;
num = num / base;
tmp[i++] = digits[res];
}
}
if (i > precision)
precision = i;