Subject: Re: lib/35401
To: None <gnats-bugs@NetBSD.org, netbsd-bugs@netbsd.org>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-bugs
Date: 01/15/2007 15:23:54
David Laight wrote:
> On Sun, Jan 14, 2007 at 11:35:02PM +0000, Christian Biere wrote:
> >  
> >  Should I commit or are there any objections?
 
> Yes - printf is too slow already any you've just made it a lot slower.

I suspect you're referring to add_digit() when you say "a lot". This
variant should be a bit faster:

static inline int
add_digit(unsigned value, unsigned int d)
{
	unsigned long ret;

	ret = value * 10;
	if (__predict_false(value > (INT_MAX - 9) / 10)) {
#if INT_MAX > (ULONG_MAX - 9) / 10
		if (ret < value)
			return -1;
#endif
		if (ret + d > INT_MAX)
			return -1;
	}
	return ret + d;
}

to_digit() is moved back to the caller. I added __predict_false()
because this check is only required for the last valid digit which
should rarely be reached anyway.

-- 
Christian