Skip to content

Commit

Permalink
serialize: speed up json pretty printing by batch writing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Jul 4, 2014
1 parent 717de50 commit 67c8a8d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/libserialize/json.rs
Expand Up @@ -299,11 +299,20 @@ fn escape_char(writer: &mut io::Writer, v: char) -> Result<(), io::IoError> {
escape_bytes(writer, buf)
}

fn spaces(writer: &mut io::Writer, n: uint) -> Result<(), io::IoError> {
for _ in range(0, n) {
try!(writer.write_str(" "));
fn spaces(wr: &mut io::Writer, mut n: uint) -> Result<(), io::IoError> {
static len: uint = 16;
static buf: [u8, ..len] = [b' ', ..len];

while n >= len {
try!(wr.write(buf));
n -= len;
}

if n > 0 {
wr.write(buf.slice_to(n))
} else {
Ok(())
}
Ok(())
}

fn fmt_number_or_null(v: f64) -> String {
Expand Down

5 comments on commit 67c8a8d

@bors
Copy link
Contributor

@bors bors commented on 67c8a8d Jul 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at erickt@67c8a8d

@bors
Copy link
Contributor

@bors bors commented on 67c8a8d Jul 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/json = 67c8a8d into auto

@bors
Copy link
Contributor

@bors bors commented on 67c8a8d Jul 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/json = 67c8a8d merged ok, testing candidate = 9f2a43c

@bors
Copy link
Contributor

@bors bors commented on 67c8a8d Jul 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9f2a43c

Please sign in to comment.