mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
refactor(parser): remove extraneous code from regex parsing (#2008)
This PR removes some code in parsing regexp flags which is extraneous:
```rs
if !ch.is_ascii_lowercase() {
self.error(diagnostics::RegExpFlag(ch, self.current_offset()));
continue;
}
```
Which is followed by:
```rs
let flag = if let Ok(flag) = RegExpFlags::try_from(ch) {
flag
} else {
self.error(diagnostics::RegExpFlag(ch, self.current_offset()));
continue;
};
```
`!ch.is_ascii_lowercase()` is equivalent to `ch < 'a' || ch > 'z'`. The
compiler implements `RegExpFlags::try_from(ch)` as `ch < 'd' || ch >
'y'` and then a jump table. So `ch.is_ascii_lowercase()` does nothing
that `RegExpFlags::try_from(ch)` doesn't do already.
https://godbolt.org/z/51GPPY9nx
(this PR built on top of #2007 for ease)
This commit is contained in:
parent
107a32ea48
commit
6996948825
1 changed files with 0 additions and 4 deletions
|
|
@ -870,10 +870,6 @@ impl<'a> Lexer<'a> {
|
||||||
|
|
||||||
while let Some(ch @ ('$' | '_' | 'a'..='z' | 'A'..='Z' | '0'..='9')) = self.peek() {
|
while let Some(ch @ ('$' | '_' | 'a'..='z' | 'A'..='Z' | '0'..='9')) = self.peek() {
|
||||||
self.current.chars.next();
|
self.current.chars.next();
|
||||||
if !ch.is_ascii_lowercase() {
|
|
||||||
self.error(diagnostics::RegExpFlag(ch, self.current_offset()));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let flag = if let Ok(flag) = RegExpFlags::try_from(ch) {
|
let flag = if let Ok(flag) = RegExpFlags::try_from(ch) {
|
||||||
flag
|
flag
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue