Subject: Re: lib/35401
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-bugs
Date: 01/15/2007 14:20:02
The following reply was made to PR lib/35401; it has been noted by GNATS.

From: Christian Biere <christianbiere@gmx.de>
To: gnats-bugs@NetBSD.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: lib/35401
Date: Mon, 15 Jan 2007 15:23:54 +0100

 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