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"
1414[dependencies ]
1515indexmap = { version = " 2.2.3" , optional = true }
1616itoa = " 1.0"
17+ memchr = { version = " 2" , default-features = false }
1718ryu = " 1.0"
1819serde = { version = " 1.0.194" , default-features = false }
1920
@@ -45,7 +46,7 @@ features = ["raw_value"]
4546[features ]
4647default = [" std" ]
4748
48- std = [" serde/std" ]
49+ std = [" memchr/std " , " serde/std" ]
4950
5051# Provide integration for heap-allocated collections without depending on the
5152# rest of the Rust standard library.
Original file line number Diff line number Diff line change @@ -415,19 +415,14 @@ impl<'a> SliceRead<'a> {
415415 }
416416
417417 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,
429425 }
430- position
431426 }
432427
433428 /// 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