Skip to content

Commit

Permalink
Merge pull request #2018 from ghaerr/console2
Browse files Browse the repository at this point in the history
[kernel] Replace atoi in ANSI console with very fast version
  • Loading branch information
ghaerr authored Sep 16, 2024
2 parents 665340a + c1cf3d5 commit 97547d1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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

0 comments on commit 97547d1

Please sign in to comment.