File tree Expand file tree Collapse file tree 2 files changed +9
-13
lines changed Expand file tree Collapse file tree 2 files changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ rust-version = "1.56"
14
14
[dependencies ]
15
15
indexmap = { version = " 2.2.3" , optional = true }
16
16
itoa = " 1.0"
17
+ memchr = { version = " 2" , default-features = false }
17
18
ryu = " 1.0"
18
19
serde = { version = " 1.0.194" , default-features = false }
19
20
@@ -45,7 +46,7 @@ features = ["raw_value"]
45
46
[features ]
46
47
default = [" std" ]
47
48
48
- std = [" serde/std" ]
49
+ std = [" memchr/std " , " serde/std" ]
49
50
50
51
# Provide integration for heap-allocated collections without depending on the
51
52
# rest of the Rust standard library.
Original file line number Diff line number Diff line change @@ -415,19 +415,14 @@ impl<'a> SliceRead<'a> {
415
415
}
416
416
417
417
fn position_of_index ( & self , i : usize ) -> Position {
418
- let mut position = Position { line : 1 , column : 0 } ;
419
- for ch in & self . slice [ ..i] {
420
- match * ch {
421
- b'\n' => {
422
- position. line += 1 ;
423
- position. column = 0 ;
424
- }
425
- _ => {
426
- position. column += 1 ;
427
- }
428
- }
418
+ let start_of_line = match memchr:: memrchr ( b'\n' , & self . slice [ ..i] ) {
419
+ Some ( position) => position + 1 ,
420
+ None => 0 ,
421
+ } ;
422
+ Position {
423
+ line : 1 + memchr:: memchr_iter ( b'\n' , & self . slice [ ..start_of_line] ) . count ( ) ,
424
+ column : i - start_of_line,
429
425
}
430
- position
431
426
}
432
427
433
428
/// The big optimization here over IoRead is that if the string contains no
You can’t perform that action at this time.
0 commit comments