File tree Expand file tree Collapse file tree 2 files changed +38
-20
lines changed Expand file tree Collapse file tree 2 files changed +38
-20
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: db377bae3a1d9b980ea6eb6f1daf3a72bdeb7b25
2
+ refs/heads/master: a2bd79a6acc9fc9f1dba6e718c9d9eda7791a277
Original file line number Diff line number Diff line change @@ -36,33 +36,51 @@ fn next_power_of_two(uint n) -> uint {
36
36
fn to_str ( mutable uint n, uint radix ) -> str
37
37
{
38
38
check ( 0 u < radix && radix <= 16 u) ;
39
- fn digit ( uint n) -> str {
39
+ fn digit ( uint n) -> char {
40
40
alt ( n) {
41
- case ( 0 u) { ret "0" ; }
42
- case ( 1 u) { ret "1" ; }
43
- case ( 2 u) { ret "2" ; }
44
- case ( 3 u) { ret "3" ; }
45
- case ( 4 u) { ret "4" ; }
46
- case ( 5 u) { ret "5" ; }
47
- case ( 6 u) { ret "6" ; }
48
- case ( 7 u) { ret "7" ; }
49
- case ( 8 u) { ret "8" ; }
50
- case ( 9 u) { ret "9" ; }
51
- case ( 10 u) { ret "a" ; }
52
- case ( 11 u) { ret " b" ; }
53
- case (12u) { ret " c" ; }
54
- case (13u) { ret " d" ; }
55
- case ( 14 u) { ret "e" ; }
56
- case ( 15 u) { ret "f" ; }
41
+ case ( 0 u) { ret '0' ; }
42
+ case ( 1 u) { ret '1' ; }
43
+ case ( 2 u) { ret '2' ; }
44
+ case ( 3 u) { ret '3' ; }
45
+ case ( 4 u) { ret '4' ; }
46
+ case ( 5 u) { ret '5' ; }
47
+ case ( 6 u) { ret '6' ; }
48
+ case ( 7 u) { ret '7' ; }
49
+ case ( 8 u) { ret '8' ; }
50
+ case ( 9 u) { ret '9' ; }
51
+ case ( 10 u) { ret 'a' ; }
52
+ case ( 11 u) { ret 'b' ; }
53
+ case ( 12 u) { ret 'c' ; }
54
+ case ( 13 u) { ret 'd' ; }
55
+ case ( 14 u) { ret 'e' ; }
56
+ case ( 15 u) { ret 'f' ; }
57
57
}
58
58
}
59
59
60
60
if ( n == 0 u) { ret "0" ; }
61
61
62
+ let uint r = 1 u;
63
+ if ( n > r) {
64
+ while ( ( r* radix) < n) {
65
+ r *= radix;
66
+ }
67
+ }
68
+
62
69
let str s = "" ;
63
70
while ( n > 0 u) {
64
- s = digit ( n % radix) + s;
65
- n /= radix;
71
+
72
+ auto i = n/r;
73
+
74
+ n -= ( i * r) ;
75
+ r /= radix;
76
+
77
+ s += digit ( i) as u8 ;
78
+ }
79
+
80
+ while ( r > 0 u) {
81
+ s += '0' as u8 ;
82
+ r /= radix;
66
83
}
84
+
67
85
ret s;
68
86
}
You can’t perform that action at this time.
0 commit comments