From d5f31fbe0b88d83756f36059ada2250e78d03acd Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 20 May 2015 23:37:18 +0100 Subject: [PATCH] xitoa: use our own int helper For stdio and perror using apps it costs us a small amount of memory. For stdio using apps in general it's free, and for non stdio apps using itoa and not sucking in the 32bit maths helpers its a big saving. --- Library/libs/xitoa.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Library/libs/xitoa.c b/Library/libs/xitoa.c index a066c10d..2c076f1d 100644 --- a/Library/libs/xitoa.c +++ b/Library/libs/xitoa.c @@ -1,10 +1,34 @@ /* - * Internal wrapper for ltostr. Ought to go away + * Internal wrapper (in theory) but used in various places it's helpful */ #include /*********************** xitoa.c ***************************/ -char *_itoa(int i) + +/* Don't go via long - the long version is expensive on an 8bit processor and + can often be avoided */ + +static char buf[7]; + +char *_uitoa(int i) { - return _ltoa((long)i); + char *p = buf + sizeof(buf); + int c; + + *--p = '\0'; + do { + c = i % 10; + i /= 10; + *--p = '0' + c; + } while(i); + return p; +} + +char *_itoa(int i) { + char *p; + if (i >= 0) + return _uitoa(i); + p = _uitoa(-i); + *--p = '-'; + return p; } -- 2.34.1