@@ -269,6 +269,7 @@ impl<'a> Tokenizer<'a> {
269
269
270
270
#[ inline]
271
271
pub fn position ( & self ) -> SourcePosition {
272
+ debug_assert ! ( self . input. is_char_boundary( self . position) ) ;
272
273
SourcePosition ( self . position )
273
274
}
274
275
@@ -308,24 +309,26 @@ impl<'a> Tokenizer<'a> {
308
309
}
309
310
310
311
#[ inline]
311
- pub fn slice_from ( & self , start_pos : SourcePosition ) -> & ' a str {
312
- & self . input [ start_pos. 0 .. self . position ]
312
+ pub ( crate ) fn slice_from ( & self , start_pos : SourcePosition ) -> & ' a str {
313
+ self . slice ( start_pos.. self . position ( ) )
313
314
}
314
315
315
316
#[ inline]
316
- pub fn slice ( & self , range : Range < SourcePosition > ) -> & ' a str {
317
- & self . input [ range. start . 0 ..range. end . 0 ]
317
+ pub ( crate ) fn slice ( & self , range : Range < SourcePosition > ) -> & ' a str {
318
+ debug_assert ! ( self . input. is_char_boundary( range. start. 0 ) ) ;
319
+ debug_assert ! ( self . input. is_char_boundary( range. end. 0 ) ) ;
320
+ unsafe { self . input . get_unchecked ( range. start . 0 ..range. end . 0 ) }
318
321
}
319
322
320
323
pub fn current_source_line ( & self ) -> & ' a str {
321
- let current = self . position ;
322
- let start = self . input [ 0 ..current]
324
+ let current = self . position ( ) ;
325
+ let start = self . slice ( SourcePosition ( 0 ) ..current)
323
326
. rfind ( |c| matches ! ( c, '\r' | '\n' | '\x0C' ) )
324
327
. map_or ( 0 , |start| start + 1 ) ;
325
- let end = self . input [ current..]
328
+ let end = self . slice ( current..SourcePosition ( self . input . len ( ) ) )
326
329
. find ( |c| matches ! ( c, '\r' | '\n' | '\x0C' ) )
327
- . map_or ( self . input . len ( ) , |end| current + end) ;
328
- & self . input [ start.. end]
330
+ . map_or ( self . input . len ( ) , |end| current. 0 + end) ;
331
+ self . slice ( SourcePosition ( start) .. SourcePosition ( end) )
329
332
}
330
333
331
334
#[ inline]
@@ -421,7 +424,7 @@ impl<'a> Tokenizer<'a> {
421
424
422
425
#[ inline]
423
426
fn next_char ( & self ) -> char {
424
- self . input [ self . position .. ] . chars ( ) . next ( ) . unwrap ( )
427
+ unsafe { self . input . get_unchecked ( self . position ( ) . 0 .. ) } . chars ( ) . next ( ) . unwrap ( )
425
428
}
426
429
427
430
// Given that a newline has been seen, advance over the newline
0 commit comments