apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davi Arnaut <d...@haxent.com.br>
Subject [patch 2/9] simpler integer to string conversion
Date Fri, 27 Apr 2007 14:29:20 GMT
Simpler and somewhat faster integer to string conversion. Emphasis on
the "simpler". Passes testfmt.

---
 srclib/apr/strings/apr_snprintf.c |   16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

Index: 2.2.x/srclib/apr/strings/apr_snprintf.c
===================================================================
--- 2.2.x.orig/srclib/apr/strings/apr_snprintf.c	2007-04-27 11:09:49.000000000 -0300
+++ 2.2.x/srclib/apr/strings/apr_snprintf.c	2007-04-27 11:09:50.000000000 -0300
@@ -370,12 +370,8 @@
      * We use a do-while loop so that we write at least 1 digit 
      */
     do {
-        register u_wide_int new_magnitude = magnitude / 10;
-
-        *--p = (char) (magnitude - new_magnitude * 10 + '0');
-        magnitude = new_magnitude;
-    }
-    while (magnitude);
+        *--p = (char) '0' + (magnitude % 10);
+    } while ((magnitude /= 10));
 
     *len = buf_end - p;
     return (p);
@@ -423,12 +419,8 @@
      * We use a do-while loop so that we write at least 1 digit 
      */
     do {
-        u_widest_int new_magnitude = magnitude / 10;
-
-        *--p = (char) (magnitude - new_magnitude * 10 + '0');
-        magnitude = new_magnitude;
-    }
-    while (magnitude);
+        *--p = (char) '0' + (magnitude % 10);
+    } while ((magnitude /= 10));
 
     *len = buf_end - p;
     return (p);

--

Mime
View raw message