File tree Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5
5
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
- refs/heads/try2: 52949fbf1876ecd03303006c534a74c5e29bc90d
8
+ refs/heads/try2: 149c976aa0b6441b93f2e2140e10e0424d39ea17
9
9
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -481,22 +481,30 @@ pub fn to_pretty_str(json: &Json) -> ~str {
481
481
io:: with_str_writer ( |wr| to_pretty_writer ( wr, json) )
482
482
}
483
483
484
+ static BUF_SIZE : uint = 64000 ;
485
+
484
486
#[ allow( missing_doc) ]
485
487
pub struct Parser {
486
488
priv rdr: @io:: Reader ,
489
+ priv buf: ~[ char ] ,
490
+ priv buf_idx : uint ,
487
491
priv ch: char ,
488
492
priv line : uint ,
489
493
priv col: uint ,
490
494
}
491
495
492
496
/// Decode a json value from an io::reader
493
497
pub fn Parser ( rdr : @io:: Reader ) -> Parser {
494
- Parser {
498
+ let mut p = Parser {
495
499
rdr : rdr,
496
- ch : rdr. read_char ( ) ,
500
+ buf : rdr. read_chars ( BUF_SIZE ) ,
501
+ buf_idx : 0 ,
502
+ ch : 0 as char ,
497
503
line : 1 ,
498
- col : 1 ,
499
- }
504
+ col : 0 ,
505
+ } ;
506
+ p. bump ( ) ;
507
+ p
500
508
}
501
509
502
510
impl Parser {
@@ -521,13 +529,26 @@ impl Parser {
521
529
fn eof ( & self ) -> bool { self . ch == -1 as char }
522
530
523
531
fn bump ( & mut self ) {
524
- self . ch = self . rdr . read_char ( ) ;
532
+ if self . eof ( ) {
533
+ return ;
534
+ }
535
+
536
+ self . col += 1 u;
537
+
538
+ if self . buf_idx >= self . buf . len ( ) {
539
+ self . buf = self . rdr . read_chars ( BUF_SIZE ) ;
540
+ if self . buf . len ( ) == 0 {
541
+ self . ch = -1 as char ;
542
+ return ;
543
+ }
544
+ self . buf_idx = 0 ;
545
+ }
546
+ self . ch = self . buf [ self . buf_idx ] ;
547
+ self . buf_idx += 1 ;
525
548
526
549
if self . ch == '\n' {
527
550
self . line += 1 u;
528
551
self . col = 1 u;
529
- } else {
530
- self . col += 1 u;
531
552
}
532
553
}
533
554
You can’t perform that action at this time.
0 commit comments