From 3fb78e29f4ae9b3e5bb19bf5a740375e90b01ceb Mon Sep 17 00:00:00 2001 From: nham Date: Wed, 6 Aug 2014 02:02:50 -0400 Subject: Use byte literals in libstd --- src/libstd/num/strconv.rs | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/libstd/num') diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index c8528e752e8..37378518dc8 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -138,12 +138,10 @@ impl_NumStrConv_Integer!(u64) // Special value strings as [u8] consts. -static INF_BUF: [u8, ..3] = ['i' as u8, 'n' as u8, 'f' as u8]; -static POS_INF_BUF: [u8, ..4] = ['+' as u8, 'i' as u8, 'n' as u8, - 'f' as u8]; -static NEG_INF_BUF: [u8, ..4] = ['-' as u8, 'i' as u8, 'n' as u8, - 'f' as u8]; -static NAN_BUF: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8]; +static INF_BUF: [u8, ..3] = [b'i', b'n', b'f']; +static POS_INF_BUF: [u8, ..4] = [b'+', b'i', b'n', b'f']; +static NEG_INF_BUF: [u8, ..4] = [b'-', b'i', b'n', b'f']; +static NAN_BUF: [u8, ..3] = [b'N', b'a', b'N']; /** * Converts an integral number to its string representation as a byte vector. @@ -201,8 +199,8 @@ pub fn int_to_str_bytes_common(num: T, radix: uint, sign: SignFormat, f: current_digit_signed }; buf[cur] = match current_digit.to_u8().unwrap() { - i @ 0..9 => '0' as u8 + i, - i => 'a' as u8 + (i - 10), + i @ 0..9 => b'0' + i, + i => b'a' + (i - 10), }; cur += 1; @@ -213,8 +211,8 @@ pub fn int_to_str_bytes_common(num: T, radix: uint, sign: SignFormat, f: // Decide what sign to put in front match sign { - SignNeg | SignAll if neg => { f('-' as u8); } - SignAll => { f('+' as u8); } + SignNeg | SignAll if neg => { f(b'-'); } + SignAll => { f(b'+'); } _ => () } @@ -350,10 +348,10 @@ pub fn float_to_str_bytes_common { - buf.push('-' as u8); + buf.push(b'-'); } SignAll => { - buf.push('+' as u8); + buf.push(b'+'); } _ => () } @@ -368,7 +366,7 @@ pub fn float_to_str_bytes_common 0) { - buf.push('.' as u8); + buf.push(b'.'); let mut dig = 0u; // calculate new digits while @@ -415,14 +413,14 @@ pub fn float_to_str_bytes_common start_fractional_digits && *buf.get(i) == '0' as u8 { + while i > start_fractional_digits && *buf.get(i) == b'0' { i -= 1; } // Only attempt to truncate digits if buf has fractional digits if i >= start_fractional_digits { // If buf ends with '.', cut that too. - if *buf.get(i) == '.' as u8 { i -= 1 } + if *buf.get(i) == b'.' { i -= 1 } // only resize buf if we actually remove digits if i < buf_max_i { @@ -465,7 +463,7 @@ pub fn float_to_str_bytes_common