[PATCH] unify itoa
Denis Vlasenko
vda.linux at googlemail.com
Sat Jul 8 11:42:05 PDT 2006
On Saturday 08 July 2006 19:45, Rob Landley wrote:
> On Saturday 08 July 2006 12:44 pm, Denis Vlasenko wrote:
> > Hi folks, Rob,
> >
> > Attached patch removes all instances of local itoa()-like
> > functions, introduces common one into libbb and uses
> > it where appropriate.
>
> Is "sprintf" really that bad? (Or xasprintf() out of our library when you
> need it to malloc?) Especially if the darn compiler actually starts doing
> intelligent string merging, which it's inching towards...
I think that some programs may print so much numerical output
that it may be important for them to do itoa more-or-less
efficiently.
sprintf is a performance disaster. In any libc I've looked into,
it _creates a custom struct FILE_, and then calls v_something_printf()
on that, which _parses format string_ with gazzilion of possible
obscure format specifiers, and _then_ it does itoa thing.
> You have a large quantity of code under #ifdef NOT_NEEDED_YET that by itself
> would make me reject this patch.
I wrote that just in case you'll want me to convert ash too.
See below.
> (What's max_unsigned_power10() doing,
> anyway, and is that really a sane way to do whatever it is?)
It calculates maximum power-of-10 which fits in unsigned int.
It does that at compile time, portably. That's why it looks funny.
gcc optimizes it out to simple 1000000000 constant
(if sizeof(unsigned)==4, that is).
> > If you want it converted too, I'll do it. itoa.c
> > already has code which can handle unsigned long long conv,
> > it is #ifdef'ed out for now. See the patch.
>
> It can handle int, and long long, but not long. On 64 bit platforms (we
> already support x86-64, and this sort of thing will only get more common to
> the point it may be a noticeable chunk of the embedded space in 3-5 years),
> these are three different sizes.
long long currently is needed for ash only, everybody else wants
itoa([unsigned] int). There are no ltoa users today.
ltoa is of course a piece of cake, can do when someone will need it.
So, do you want me to
a) remove #ifdef NOT_NEEDED_YET part
or
b) enable it and use it in ash?
--
vda
More information about the busybox
mailing list