Skip to content

Commit

Permalink
Merge pull request #472 from dtolnay/ryu
Browse files Browse the repository at this point in the history
Switch from dtoa to ryu
  • Loading branch information
dtolnay authored Aug 14, 2018
2 parents bf352eb + 6492b75 commit 19276df
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ appveyor = { repository = "serde-rs/json" }
serde = "1.0.60"
indexmap = { version = "1.0", optional = true }
itoa = "0.4"
dtoa = "0.4"
ryu = "0.2"

[dev-dependencies]
compiletest_rs = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@

#[macro_use]
extern crate serde;
extern crate dtoa;
extern crate ryu;
#[cfg(feature = "preserve_order")]
extern crate indexmap;
extern crate itoa;
Expand Down
6 changes: 2 additions & 4 deletions src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt::{self, Debug, Display};

#[cfg(feature = "arbitrary_precision")]
use dtoa;
use ryu;
#[cfg(feature = "arbitrary_precision")]
use itoa;
#[cfg(feature = "arbitrary_precision")]
Expand Down Expand Up @@ -266,9 +266,7 @@ impl Number {
}
#[cfg(feature = "arbitrary_precision")]
{
let mut buf = Vec::new();
dtoa::write(&mut buf, f).unwrap();
String::from_utf8(buf).unwrap()
ryu::Buffer::new().format(f).to_owned()
}
};
Some(Number { n: n })
Expand Down
10 changes: 7 additions & 3 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use std::str;
use super::error::{Error, ErrorCode, Result};
use serde::ser::{self, Impossible};

use dtoa;
use itoa;
use ryu;

#[cfg(feature = "arbitrary_precision")]
use serde::Serialize;
Expand Down Expand Up @@ -1554,7 +1554,9 @@ pub trait Formatter {
where
W: io::Write,
{
dtoa::write(writer, value).map(drop)
let mut buffer = ryu::Buffer::new();
let s = buffer.format(value);
writer.write_all(s.as_bytes())
}

/// Writes a floating point value like `-31.26e+12` to the specified writer.
Expand All @@ -1563,7 +1565,9 @@ pub trait Formatter {
where
W: io::Write,
{
dtoa::write(writer, value).map(drop)
let mut buffer = ryu::Buffer::new();
let s = buffer.format(value);
writer.write_all(s.as_bytes())
}

/// Writes a number that has already been rendered to a string.
Expand Down

0 comments on commit 19276df

Please sign in to comment.