Skip to content

Commit ac4cb89

Browse files
committed
0.8.5 more perf? more perf!
1 parent 09e8df8 commit ac4cb89

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/codegen.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub trait Generator {
6363
self.write_char(b'"');
6464
}
6565

66+
#[inline(always)]
6667
fn write_string(&mut self, string: &str) {
6768
self.write_char(b'"');
6869

@@ -80,7 +81,7 @@ pub trait Generator {
8081
match num.classify() {
8182
FpCategory::Normal |
8283
FpCategory::Subnormal => {
83-
if num.fract() == 0.0 && num < 1e19 {
84+
if num.fract() == 0.0 && num.abs() < 1e19 {
8485
itoa::write(self.get_buffer(), num as i64).unwrap();
8586
} else {
8687
let abs = num.abs();

src/parser.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,16 @@ impl<'a> Parser<'a> {
393393

394394
fn read_number_with_fraction(&mut self, mut num: f64) -> JsonResult<f64> {
395395
if next_byte!(self || return Ok(num)) == b'.' {
396-
let mut precision = 0.1;
396+
let mut p = 1u64;
397+
let mut f = 0u64;
397398

399+
// FIXME: prevent overflowing!
398400
read_num!(self, digit, {
399-
num += (digit as f64) * precision;
400-
precision /= 10.0;
401+
f = (f << 1) + (f << 3) + digit as u64;
402+
p = (p << 1) + (p << 3);
401403
});
404+
405+
num += (f as f64) / (p as f64);
402406
} else {
403407
self.index -= 1;
404408
}

0 commit comments

Comments
 (0)