[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] trivial: Optimize printnum


  • To: xen-changelog@xxxxxxxxxxxxxxxxxxx
  • From: Xen patchbot-unstable <patchbot@xxxxxxx>
  • Date: Tue, 19 Feb 2013 15:22:12 +0000
  • Delivery-date: Tue, 19 Feb 2013 15:22:18 +0000
  • List-id: "Change log for Mercurial \(receive only\)" <xen-changelog.lists.xen.org>

# HG changeset patch
# User Frediano Ziglio <frediano.ziglio@xxxxxxxxxx>
# Date 1360935126 0
# Node ID 9dd3f5b570b9c1ca3f1c923ef85dc946386d2cbe
# Parent  980b1273c7116aa43085992888a1bbefa0d17de5
trivial: Optimize printnum

Reuse the string of hexadecimal numbers to simplify printnum implementation

Signed-off-by: Frediano Ziglio <frediano.ziglio@xxxxxxxxxx>
Acked-by: Keir Fraser <keir@xxxxxxx>
Committed-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---


diff -r 980b1273c711 -r 9dd3f5b570b9 tools/firmware/hvmloader/util.c
--- a/tools/firmware/hvmloader/util.c   Fri Feb 15 13:32:06 2013 +0000
+++ b/tools/firmware/hvmloader/util.c   Fri Feb 15 13:32:06 2013 +0000
@@ -315,23 +315,15 @@ cpuid(uint32_t idx, uint32_t *eax, uint3
         : "0" (idx) );
 }
 
+static const char hex_digits[] = "0123456789abcdef";
+
 /* Write a two-character hex representation of 'byte' to digits[].
    Pre-condition: sizeof(digits) >= 2 */
 void
 byte_to_hex(char *digits, uint8_t byte)
 {
-    uint8_t nybbel = byte >> 4;
-
-    if ( nybbel > 9 )
-        digits[0] = 'a' + nybbel-10;
-    else
-        digits[0] = '0' + nybbel;
-
-    nybbel = byte & 0x0f;
-    if ( nybbel > 9 )
-        digits[1] = 'a' + nybbel-10;
-    else
-        digits[1] = '0' + nybbel;
+    digits[0] = hex_digits[byte >> 4];
+    digits[1] = hex_digits[byte & 0x0f];
 }
 
 /* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
@@ -518,13 +510,13 @@ void pci_write(uint32_t devfn, uint32_t 
     }
 }
 
-static char *printnum(char *p, unsigned long num, int base)
+static char *printnum(char *p, unsigned long num, unsigned base)
 {
     unsigned long n;
 
     if ( (n = num/base) > 0 )
         p = printnum(p, n, base);
-    *p++ = "0123456789abcdef"[(int)(num % base)];
+    *p++ = hex_digits[num % base];
     *p = '\0';
     return p;
 }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.