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 1/9] Early assignment yields better code
Date Fri, 27 Apr 2007 14:29:19 GMT
Early assignment of the to-be-converted number yields better code and avoids
ugly casts.

---
 srclib/apr/strings/apr_snprintf.c |   14 +++-----------
 1 file changed, 3 insertions(+), 11 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:49.000000000 -0300
@@ -343,10 +343,9 @@
                      register apr_size_t *len)
 {
     register char *p = buf_end;
-    register u_wide_int magnitude;
+    register u_wide_int magnitude = num;
 
     if (is_unsigned) {
-        magnitude = (u_wide_int) num;
         *is_negative = FALSE;
     }
     else {
@@ -363,11 +362,8 @@
          */
         if (*is_negative) {
             wide_int t = num + 1;
-
             magnitude = ((u_wide_int) -t) + 1;
         }
-        else
-            magnitude = (u_wide_int) num;
     }
 
     /*
@@ -390,20 +386,19 @@
                      register apr_size_t *len)
 {
     register char *p = buf_end;
-    u_widest_int magnitude;
+    u_widest_int magnitude = num;
 
     /*
      * We see if we can use the faster non-quad version by checking the
      * number against the largest long value it can be. If <=, we
      * punt to the quicker version.
      */
-    if (((u_widest_int)num <= (u_widest_int)ULONG_MAX && is_unsigned) 
+    if ((magnitude <= ULONG_MAX && is_unsigned)
         || (num <= LONG_MAX && num >= LONG_MIN && !is_unsigned))
             return(conv_10( (wide_int)num, is_unsigned, is_negative,
                buf_end, len));
 
     if (is_unsigned) {
-        magnitude = (u_widest_int) num;
         *is_negative = FALSE;
     }
     else {
@@ -420,11 +415,8 @@
          */
         if (*is_negative) {
             widest_int t = num + 1;
-
             magnitude = ((u_widest_int) -t) + 1;
         }
-        else
-            magnitude = (u_widest_int) num;
     }
 
     /*

--

Mime
View raw message