@@ -274,6 +274,7 @@ impl<'a> Tokenizer<'a> {
274
274
275
275
#[ inline]
276
276
pub fn position ( & self ) -> SourcePosition {
277
+ debug_assert ! ( self . input. is_char_boundary( self . position) ) ;
277
278
SourcePosition ( self . position )
278
279
}
279
280
@@ -313,24 +314,26 @@ impl<'a> Tokenizer<'a> {
313
314
}
314
315
315
316
#[ inline]
316
- pub fn slice_from ( & self , start_pos : SourcePosition ) -> & ' a str {
317
- & self . input [ start_pos. 0 .. self . position ]
317
+ pub ( crate ) fn slice_from ( & self , start_pos : SourcePosition ) -> & ' a str {
318
+ self . slice ( start_pos.. self . position ( ) )
318
319
}
319
320
320
321
#[ inline]
321
- pub fn slice ( & self , range : Range < SourcePosition > ) -> & ' a str {
322
- & self . input [ range. start . 0 ..range. end . 0 ]
322
+ pub ( crate ) fn slice ( & self , range : Range < SourcePosition > ) -> & ' a str {
323
+ debug_assert ! ( self . input. is_char_boundary( range. start. 0 ) ) ;
324
+ debug_assert ! ( self . input. is_char_boundary( range. end. 0 ) ) ;
325
+ unsafe { self . input . get_unchecked ( range. start . 0 ..range. end . 0 ) }
323
326
}
324
327
325
328
pub fn current_source_line ( & self ) -> & ' a str {
326
- let current = self . position ;
327
- let start = self . input [ 0 ..current]
329
+ let current = self . position ( ) ;
330
+ let start = self . slice ( SourcePosition ( 0 ) ..current)
328
331
. rfind ( |c| matches ! ( c, '\r' | '\n' | '\x0C' ) )
329
332
. map_or ( 0 , |start| start + 1 ) ;
330
- let end = self . input [ current..]
333
+ let end = self . slice ( current..SourcePosition ( self . input . len ( ) ) )
331
334
. find ( |c| matches ! ( c, '\r' | '\n' | '\x0C' ) )
332
- . map_or ( self . input . len ( ) , |end| current + end) ;
333
- & self . input [ start.. end]
335
+ . map_or ( self . input . len ( ) , |end| current. 0 + end) ;
336
+ self . slice ( SourcePosition ( start) .. SourcePosition ( end) )
334
337
}
335
338
336
339
#[ inline]
@@ -426,7 +429,7 @@ impl<'a> Tokenizer<'a> {
426
429
427
430
#[ inline]
428
431
fn next_char ( & self ) -> char {
429
- self . input [ self . position .. ] . chars ( ) . next ( ) . unwrap ( )
432
+ unsafe { self . input . get_unchecked ( self . position ( ) . 0 .. ) } . chars ( ) . next ( ) . unwrap ( )
430
433
}
431
434
432
435
// Given that a newline has been seen, advance over the newline
0 commit comments