Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up integer printing #87

Merged
merged 1 commit into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ serde = "^0.7.0"
num-traits = "~0.1.32"
clippy = { version = "^0.*", optional = true }
linked-hash-map = { version = "0.0.11", optional = true }
itoa = "0.1"
1 change: 1 addition & 0 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
extern crate num_traits;
extern crate core;
extern crate serde;
extern crate itoa;
#[cfg(feature = "preserve_order")]
extern crate linked_hash_map;

Expand Down
22 changes: 12 additions & 10 deletions json/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::num::FpCategory;
use serde::ser;
use super::error::{Error, ErrorCode, Result};

use itoa;

/// A structure for serializing Rust values into JSON.
pub struct Serializer<W, F=CompactFormatter> {
writer: W,
Expand Down Expand Up @@ -77,52 +79,52 @@ impl<W, F> ser::Serializer for Serializer<W, F>

#[inline]
fn serialize_isize(&mut self, value: isize) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
fn serialize_i8(&mut self, value: i8) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
fn serialize_i16(&mut self, value: i16) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
fn serialize_i32(&mut self, value: i32) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
fn serialize_i64(&mut self, value: i64) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
fn serialize_usize(&mut self, value: usize) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
fn serialize_u8(&mut self, value: u8) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
fn serialize_u16(&mut self, value: u16) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
fn serialize_u32(&mut self, value: u32) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
fn serialize_u64(&mut self, value: u64) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
itoa::write(&mut self.writer, value).map_err(From::from)
}

#[inline]
Expand Down