# HG changeset patch # User asl # Date 1172703671 0 # Node ID 5bcdb1b5eb692af6febd8bef29edaca1e8a8c0c4 # Parent 6f3a847c9adcc9a68626d3a70a7162822196b48d * src/output/vfnprintf.cxx (vfnprintf): while formatting integers in decimal, convert the value to unsigned long from unsigned long long before processing, unless we actually print long long argument. This tremendously speeds-up the formatting. diff --git a/packages/language/c/libc/stdio/current/ChangeLog b/packages/language/c/libc/stdio/current/ChangeLog --- a/packages/language/c/libc/stdio/current/ChangeLog +++ b/packages/language/c/libc/stdio/current/ChangeLog @@ -1,3 +1,10 @@ +2007-02-05 Sergei Organov + + * src/output/vfnprintf.cxx (vfnprintf): while formatting integers + in decimal, convert the value to unsigned long from unsigned long + long before processing, unless we actually print long long + argument. This tremendously speeds-up the formatting. + 2007-01-16 Sergei Organov Speed-up [v]s[n]printf() functions by a factor of about 2+. In diff --git a/packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx b/packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx --- a/packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx +++ b/packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx @@ -553,14 +553,26 @@ number: if ((dprec = pre break; case DEC: - /* many numbers are 1 digit */ - while (_uquad >= 10) { - /* The following is usually faster than using a modulo */ - u_quad_t next = _uquad / 10; - *--cp = to_char(_uquad - (next * 10)); - _uquad = next; + if (!(flags & QUADINT)) { + /* many numbers are 1 digit */ + unsigned long v = (unsigned long)_uquad; + while (v >= 10) { + /* The following is usually faster than using a modulo */ + unsigned long next = v / 10; + *--cp = to_char(v - (next * 10)); + v = next; + } + *--cp = to_char(v); } - *--cp = to_char(_uquad); + else { + while (_uquad >= 10) { + /* The following is usually faster than using a modulo */ + u_quad_t next = _uquad / 10; + *--cp = to_char(_uquad - (next * 10)); + _uquad = next; + } + *--cp = to_char(_uquad); + } break; case HEX: