Skip to content

Commit 50c08db

Browse files
committed
Merge pull request #5178 from catamorphism/constant-buffers
core: Address XXX, make static constants for strings used when stringify...
2 parents 02a4b5b + 405a35c commit 50c08db

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/libcore/num/strconv.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -478,17 +478,16 @@ pub pure fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
478478
}
479479
}
480480

481-
// XXX: Bytevector constant from str
482481
if special {
483-
if buf == str::to_bytes("inf") || buf == str::to_bytes("+inf") {
482+
if buf == str::inf_buf || buf == str::positive_inf_buf {
484483
return NumStrConv::inf();
485-
} else if buf == str::to_bytes("-inf") {
484+
} else if buf == str::negative_inf_buf {
486485
if negative {
487486
return NumStrConv::neg_inf();
488487
} else {
489488
return None;
490489
}
491-
} else if buf == str::to_bytes("NaN") {
490+
} else if buf == str::nan_buf {
492491
return NumStrConv::NaN();
493492
}
494493
}

src/libcore/str.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,13 @@ const tag_five_b: uint = 248u;
18321832
const max_five_b: uint = 67108864u;
18331833
const tag_six_b: uint = 252u;
18341834

1835+
// Constants used for converting strs to floats
1836+
pub const inf_buf: [u8*3] = ['i' as u8, 'n' as u8, 'f' as u8];
1837+
pub const positive_inf_buf: [u8*4] = ['+' as u8, 'i' as u8,
1838+
'n' as u8, 'f' as u8];
1839+
pub const negative_inf_buf: [u8*4] = ['-' as u8, 'i' as u8,
1840+
'n' as u8, 'f' as u8];
1841+
pub const nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8];
18351842

18361843
/**
18371844
* Work with the byte buffer of a string.

0 commit comments

Comments
 (0)