Skip to content

Commit fcd0556

Browse files
committed
Update itoa from 0.4 to 1.0.
Update itoa from 0.4 to 1.0. itoa::Buffer::new() allocates the necessary space on the stack automatically, and usage is similar to ryu now.
1 parent 4523cd9 commit fcd0556

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ hashbrown = "0.9"
2020
lazy_static = "1.4.0"
2121
regex = "1.3"
2222
regex-syntax = "0.6.22"
23-
itoa = "0.4"
23+
itoa = "1.0"
2424
ryu = "1.0"
2525
libc = "0.2"
2626
jemallocator = { version = "0.3", optional = true }

src/runtime/str_impl.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,6 @@ impl Inline {
9393
)
9494
}
9595
}
96-
97-
#[inline(always)]
98-
fn itoa(i: Int) -> Option<Inline> {
99-
if i > 999999999999999 || i < -99999999999999 {
100-
return None;
101-
}
102-
let mut res = 0u128;
103-
let buf =
104-
unsafe { slice::from_raw_parts_mut((&mut res as *mut _ as *mut u8).offset(1), 15) };
105-
let len = itoa::write(buf, i).unwrap();
106-
Some(Inline(res | ((len << 3) | StrTag::Inline as usize) as u128))
107-
}
10896
}
10997

11098
#[derive(Clone)]
@@ -926,12 +914,9 @@ impl<'a> From<String> for Str<'a> {
926914

927915
impl<'a> From<Int> for Str<'a> {
928916
fn from(i: Int) -> Str<'a> {
929-
if let Some(i) = Inline::itoa(i) {
930-
return Str::from_rep(i.into());
931-
}
932-
let mut buf = [0u8; 21];
933-
let n = itoa::write(&mut buf[..], i).unwrap();
934-
Buf::read_from_bytes(&buf[..n]).into_str()
917+
let mut itoabuf = itoa::Buffer::new();
918+
let s = itoabuf.format(i);
919+
Buf::read_from_bytes(&s.as_bytes()).into_str()
935920
}
936921
}
937922

0 commit comments

Comments
 (0)