changeset 2366:5bcdb1b5eb69

* 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.
author asl
date Wed, 28 Feb 2007 23:01:11 +0000
parents 6f3a847c9adc
children 6f59b6d486cd
files packages/language/c/libc/stdio/current/ChangeLog packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx
diffstat 2 files changed, 26 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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  <osv@javad.com>
+
+	* 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  <osv@javad.com>
 
 	Speed-up [v]s[n]printf() functions by a factor of about 2+. In
--- 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: