You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/swc_ecma_parser/src/lexer/mod.rs
+32-13
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@
2
2
3
3
use std::{cell::RefCell, char, iter::FusedIterator, mem::transmute, rc::Rc};
4
4
5
+
use arrayvec::ArrayVec;
5
6
use either::Either::{Left,Right};
6
-
use smallvec::{smallvec,SmallVec};
7
7
use swc_atoms::{Atom,AtomStoreCell};
8
8
use swc_common::{
9
9
comments::Comments,
@@ -52,7 +52,7 @@ impl From<u32> for Char {
52
52
}
53
53
}
54
54
55
-
pub(crate)structCharIter(SmallVec<[char;7]>);
55
+
pub(crate)structCharIter(ArrayVec<char,12>);
56
56
57
57
/// Ported from https://github.com/web-infra-dev/oxc/blob/99a4816ce7b6132b2667257984f9d92ae3768f03/crates/oxc_parser/src/lexer/mod.rs#L1349-L1374
58
58
implIntoIteratorforChar{
@@ -67,9 +67,16 @@ impl IntoIterator for Char {
67
67
// }
68
68
69
69
CharIter(match char::from_u32(self.0){
70
-
Some(c) => smallvec![c],
70
+
Some(c) => {
71
+
letmut buf = ArrayVec::new();
72
+
// Safety: we can make sure that `buf` has enough capacity
73
+
unsafe{
74
+
buf.push_unchecked(c);
75
+
}
76
+
buf
77
+
}
71
78
None => {
72
-
letmut buf = smallvec![];
79
+
letmut buf = ArrayVec::new();
73
80
74
81
let high = self.0&0xffff0000 >> 16;
75
82
@@ -78,19 +85,31 @@ impl IntoIterator for Char {
78
85
// The second code unit of a surrogate pair is always in the range from 0xDC00
79
86
// to 0xDFFF, and is called a low surrogate or a trail surrogate.
80
87
if !(0xdc00..=0xdfff).contains(&low){
81
-
buf.push('\\');
82
-
buf.push('u');
83
-
buf.extend(format!("{high:x}").chars());
84
-
buf.push('\\');
85
-
buf.push('u');
86
-
buf.extend(format!("{low:x}").chars());
88
+
// Safety: we can make sure that `buf` has enough capacity
0 commit comments