@@ -187,15 +187,7 @@ pub trait Stream: Offset<<Self as Stream>::Checkpoint> + crate::lib::std::fmt::D
187
187
///
188
188
fn next_slice ( & mut self , offset : usize ) -> Self :: Slice ;
189
189
/// Split off a slice of tokens from the input
190
- #[ inline( always) ]
191
- fn peek_slice ( & self , offset : usize ) -> ( Self , Self :: Slice )
192
- where
193
- Self : Clone ,
194
- {
195
- let mut peek = self . clone ( ) ;
196
- let slice = peek. next_slice ( offset) ;
197
- ( peek, slice)
198
- }
190
+ fn peek_slice ( & self , offset : usize ) -> Self :: Slice ;
199
191
200
192
/// Advance to the end of the stream
201
193
#[ inline( always) ]
@@ -208,7 +200,7 @@ pub trait Stream: Offset<<Self as Stream>::Checkpoint> + crate::lib::std::fmt::D
208
200
where
209
201
Self : Clone ,
210
202
{
211
- self . peek_slice ( self . eof_offset ( ) ) . 1
203
+ self . peek_slice ( self . eof_offset ( ) )
212
204
}
213
205
214
206
/// Save the current parse location within the stream
@@ -281,6 +273,11 @@ where
281
273
* self = next;
282
274
slice
283
275
}
276
+ #[ inline( always) ]
277
+ fn peek_slice ( & self , offset : usize ) -> Self :: Slice {
278
+ let ( slice, _next) = self . split_at ( offset) ;
279
+ slice
280
+ }
284
281
285
282
#[ inline( always) ]
286
283
fn checkpoint ( & self ) -> Self :: Checkpoint {
@@ -361,6 +358,11 @@ impl<'i> Stream for &'i str {
361
358
* self = next;
362
359
slice
363
360
}
361
+ #[ inline( always) ]
362
+ fn peek_slice ( & self , offset : usize ) -> Self :: Slice {
363
+ let ( slice, _next) = self . split_at ( offset) ;
364
+ slice
365
+ }
364
366
365
367
#[ inline( always) ]
366
368
fn checkpoint ( & self ) -> Self :: Checkpoint {
@@ -443,6 +445,14 @@ where
443
445
self . 1 = end_offset;
444
446
( s, start_offset, end_offset)
445
447
}
448
+ #[ inline( always) ]
449
+ fn peek_slice ( & self , offset : usize ) -> Self :: Slice {
450
+ let byte_offset = ( offset + self . 1 ) / 8 ;
451
+ let end_offset = ( offset + self . 1 ) % 8 ;
452
+ let s = self . 0 . peek_slice ( byte_offset) ;
453
+ let start_offset = self . 1 ;
454
+ ( s, start_offset, end_offset)
455
+ }
446
456
447
457
#[ inline( always) ]
448
458
fn checkpoint ( & self ) -> Self :: Checkpoint {
0 commit comments