Browse Source

speed up hex itoa conversion

ipatix 7 years ago
parent
commit
2b02db9a38
1 changed files with 13 additions and 5 deletions
  1. 13
    5
      src/agb_debug/agb_debug.c

+ 13
- 5
src/agb_debug/agb_debug.c View File

69
         value = -value;
69
         value = -value;
70
     }
70
     }
71
     /* This builds the string back to front ... */
71
     /* This builds the string back to front ... */
72
-    do {
73
-        u32 digit = value % radix;
74
-        * (pbuffer++) = (digit < 10 ? '0' + digit : (uppercase ? 'A' : 'a') + digit - 10);
75
-        value /= radix;
76
-    } while (value > 0);
72
+    if (radix == 16) {
73
+        do {
74
+            u32 digit = value & 0xF;
75
+            * (pbuffer++) = (digit < 10 ? '0' + digit : (uppercase ? 'A' : 'a') + digit - 10);
76
+            value >>= 4;
77
+        } while (value > 0);
78
+    } else {
79
+        do {
80
+            u32 digit = value % radix;
81
+            * (pbuffer++) = (digit < 10 ? '0' + digit : (uppercase ? 'A' : 'a') + digit - 10);
82
+            value /= radix;
83
+        } while (value > 0);
84
+    }
77
     for (i = (pbuffer - buffer); i < zero_pad; i++)
85
     for (i = (pbuffer - buffer); i < zero_pad; i++)
78
         * (pbuffer++) = '0';
86
         * (pbuffer++) = '0';
79
     if (negative)
87
     if (negative)