From b6732af9d7bc6a9545a8f59704d146d98f412042 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 5 Apr 2023 07:25:08 -0500 Subject: [PATCH] Use sprintf() instead of itoa(). Somebody's actually building toybox with cygwin, which pollutes the namespace with leftover DOS stuff. This makes the fast path take twice as long, but the test has a 10 second timeout and still takes under a second on my 10 year old laptop. While we're there, use long instead of int (should run at same speed). --- toys/lsb/seq.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/toys/lsb/seq.c b/toys/lsb/seq.c index 7a931c64..b44d05c6 100644 --- a/toys/lsb/seq.c +++ b/toys/lsb/seq.c @@ -52,24 +52,6 @@ static double parsef(char *s) return xstrtod(s); } -// fast integer conversion to decimal string -// TODO move to lib? -static char *itoa(char *s, int i) -{ - char buf[16], *ff = buf; - unsigned n = i; - - if (i<0) { - *s++ = '-'; - n = -i; - } - do *ff++ = '0'+n%10; while ((n /= 10)); - do *s++ = *--ff; while (ff>buf); - *s++ = '\n'; - - return s; -} - static char *flush_toybuf(char *ss) { if (ss-toybuf0) for (; ii<=len; ii += inc) - ss = flush_toybuf(itoa(ss, ii)); + ss = flush_toybuf(ss+sprintf(ss, "%ld\n", ii)); else if (inc<0) for (; ii>=len; ii += inc) - ss = flush_toybuf(itoa(ss, ii)); + ss = flush_toybuf(ss+sprintf(ss, "%ld\n", ii)); if (ss != toybuf) xwrite(1, toybuf, ss-toybuf); return; -- 2.39.2