File tree 4 files changed +5
-17
lines changed
crates/swc_ecma_fast_parser/src/lexer
4 files changed +5
-17
lines changed Original file line number Diff line number Diff line change @@ -149,18 +149,6 @@ impl<'a> Cursor<'a> {
149
149
unsafe { self . input . get_unchecked ( self . pos as usize ..) }
150
150
}
151
151
152
- /// Get a slice of the input
153
- #[ inline( always) ]
154
- pub fn slice ( & self , start : u32 , end : u32 ) -> & ' a [ u8 ] {
155
- let real_start = start. min ( self . len ) ;
156
- let real_end = end. min ( self . len ) ;
157
- // SAFETY: We've validated bounds
158
- unsafe {
159
- self . input
160
- . get_unchecked ( real_start as usize ..real_end as usize )
161
- }
162
- }
163
-
164
152
/// Get a slice of the input without bounds checking.
165
153
///
166
154
/// # Safety
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ impl Lexer<'_> {
125
125
let end = self . cursor . position ( ) ;
126
126
127
127
if end > start {
128
- let slice = self . cursor . slice ( start, end) ;
128
+ let slice = unsafe { self . cursor . slice_unchecked ( start, end) } ;
129
129
text. push_str ( unsafe { std:: str:: from_utf8_unchecked ( slice) } ) ;
130
130
}
131
131
}
@@ -149,7 +149,7 @@ impl Lexer<'_> {
149
149
150
150
// Extract the raw text
151
151
let end_idx = self . cursor . position ( ) ;
152
- let raw_bytes = self . cursor . slice ( start_idx, end_idx) ;
152
+ let raw_bytes = unsafe { self . cursor . slice_unchecked ( start_idx, end_idx) } ;
153
153
let raw_str = unsafe { std:: str:: from_utf8_unchecked ( raw_bytes) } ;
154
154
155
155
let span = self . span ( ) ;
Original file line number Diff line number Diff line change @@ -624,7 +624,7 @@ impl Lexer<'_> {
624
624
}
625
625
let end = self . cursor . position ( ) ;
626
626
let shebang_str =
627
- unsafe { std:: str:: from_utf8_unchecked ( self . cursor . slice ( start, end) ) } ;
627
+ unsafe { std:: str:: from_utf8_unchecked ( self . cursor . slice_unchecked ( start, end) ) } ;
628
628
629
629
return Ok ( Token :: new (
630
630
TokenType :: Shebang ,
Original file line number Diff line number Diff line change @@ -238,7 +238,7 @@ impl Lexer<'_> {
238
238
// Add all these characters at once
239
239
let end = self . cursor . position ( ) ;
240
240
if end > start {
241
- let slice = self . cursor . slice ( start, end) ;
241
+ let slice = unsafe { self . cursor . slice_unchecked ( start, end) } ;
242
242
value. push_str ( unsafe { std:: str:: from_utf8_unchecked ( slice) } ) ;
243
243
}
244
244
} else {
@@ -252,7 +252,7 @@ impl Lexer<'_> {
252
252
253
253
// Extract the raw template (including backticks)
254
254
let end_idx = self . cursor . position ( ) ;
255
- let raw_bytes = self . cursor . slice ( start_idx, end_idx) ;
255
+ let raw_bytes = unsafe { self . cursor . slice_unchecked ( start_idx, end_idx) } ;
256
256
let raw_str = unsafe { std:: str:: from_utf8_unchecked ( raw_bytes) } ;
257
257
258
258
let span = self . span ( ) ;
You can’t perform that action at this time.
0 commit comments