clean and opti

This commit is contained in:
starnakin 2023-07-25 09:48:20 +02:00
parent 2b97d38b7e
commit 09e0d32c15
6 changed files with 11 additions and 26 deletions

View File

@ -7,7 +7,7 @@ free_tab(tab)
if ([tmp] == 0) if ([tmp] == 0)
return; return;
free([tmp]); free([tmp]);
tmp = tmp + 1; tmp++;
} }
return free(tab); return free(tab);
} }

View File

@ -6,6 +6,6 @@ memset(tab, size, value)
if (i == size) if (i == size)
return (tab); return (tab);
[tab + i] = value; [tab + i] = value;
i = i + 1; i++;
} }
} }

View File

@ -9,7 +9,7 @@ ntoa_get_size(number)
if (number == 0) if (number == 0)
return (size); return (size);
number = number / 10; number = number / 10;
size = size + 1; size++;
} }
} }
@ -29,7 +29,7 @@ ntoa(number)
{ {
if (number == 0) if (number == 0)
return (str); return (str);
size = size - 1; size--;
[str + size] = number % 10 + '0'; [str + size] = number % 10 + '0';
number = number / 10; number = number / 10;
} }

View File

@ -1,18 +1,3 @@
ntoa_get_size(number)
{
local size = 0;
if (number == 0)
return 1;
loop
{
if (number == 0)
return (size);
number = number / 10;
size = size + 1;
}
}
ntoa_s(number) ntoa_s(number)
{ {
local str, sign, size; local str, sign, size;
@ -24,7 +9,7 @@ ntoa_s(number)
} }
size = ntoa_get_size(number); size = ntoa_get_size(number);
if (sign) if (sign)
size = size + 1; size++;
str = galloc(size + 1); str = galloc(size + 1);
if (str == 0) if (str == 0)
return (0); return (0);
@ -39,6 +24,6 @@ ntoa_s(number)
return (str); return (str);
[str + size - 1] = number % 10 + '0'; [str + size - 1] = number % 10 + '0';
number = number / 10; number = number / 10;
size = size - 1; size--;
} }
} }

View File

@ -1,14 +1,14 @@
putstr(str) putstr(str)
{ {
local i = 0; local tmp = str;
if (str == NULL) { if (str == NULL) {
putstr("(null)"); putstr("(null)");
return NULL; return NULL;
} }
loop { loop {
if ([str + i] == 0) if ([tmp] == 0)
return str; return str;
putchar([str + i]); putchar([tmp]);
i = i + 1; tmp++;
} }
} }

View File

@ -10,7 +10,7 @@ puttab_str(tab)
putchar('"'); putchar('"');
putstr([tab]); putstr([tab]);
putchar('"'); putchar('"');
tab = tab + 1; tab++;
if ([tab] != 0) if ([tab] != 0)
putstr(", "); putstr(", ");
} }