#[doc(hidden)]
pub trait FastFormat {
fn fast_push(self, output: &mut String);
}
macro_rules! impl_int {
($($t:ty),*) => {
$(
impl FastFormat for $t {
#[inline]
fn fast_push(self, output: &mut String) {
let mut buf = itoa::Buffer::new();
output.push_str(buf.format(self));
}
}
)*
};
}
impl_int!(
u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize
);
impl FastFormat for f32 {
#[inline]
fn fast_push(self, output: &mut String) {
let mut buf = ryu::Buffer::new();
output.push_str(buf.format(self));
}
}
impl FastFormat for f64 {
#[inline]
fn fast_push(self, output: &mut String) {
let mut buf = ryu::Buffer::new();
output.push_str(buf.format(self));
}
}
#[inline]
pub(crate) fn push_f64_compact(output: &mut String, value: f64) {
if value.is_finite() && value.fract() == 0.0 && value.abs() < 9_007_199_254_740_992.0 {
(value as i64).fast_push(output);
} else {
value.fast_push(output);
}
}