Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kernel] Replace atoi in ANSI console with very fast version #2018

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions elks/arch/i86/drivers/char/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ chr_drv.a: $(OBJS)
KeyMaps/keymaps.h:
$(MAKE) -C KeyMaps keymaps.h

dircon.o: console.c
console-direct.o: console.c

bioscon.o: console.c
console-direct-pc98.o: console.c

console-bios.o: console.c

#########################################################################
# Standard commands.
Expand Down
4 changes: 2 additions & 2 deletions elks/arch/i86/drivers/char/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ static int parm2(register unsigned char *buf)
return parm1(buf);
}

static void itoaQueue(int i)
static void itoaQueue(unsigned int i)
{
unsigned char a[6];
unsigned char *b = a + sizeof(a) - 1;

*b = 0;
do {
*--b = '0' + (i % 10);
*--b = (i % 10) + '0';
i /= 10;
} while (i);
while (*b)
Expand Down
9 changes: 7 additions & 2 deletions elks/lib/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ long simple_strtol(const char *s, int base)
return (neg == '-') ? -result: result;
}

int atoi(const char *number)
/* no leading space or -/+ handling, needs to be fast */
int atoi(const char *s)
{
return (int)simple_strtol(number, 10);
int n = 0;

while ((unsigned) (*s - '0') <= 9u)
n = n * 10 + *s++ - '0';
return n;
}

#ifndef __HAVE_ARCH_STRCPY
Expand Down
Loading