-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Rework RegExp struct to include bitflags field #1837
Conversation
This commit fixes/closes boa-dev#1819.
Codecov Report
@@ Coverage Diff @@
## main #1837 +/- ##
==========================================
- Coverage 55.67% 55.67% -0.01%
==========================================
Files 201 201
Lines 17375 17368 -7
==========================================
- Hits 9674 9670 -4
+ Misses 7701 7698 -3
Continue to review full report at Codecov.
|
VM implementation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking very good! I added some suggestions :)
let mut dot_all = false; | ||
let mut unicode = false; | ||
let mut sticky = false; | ||
let mut flags = RegExpFlags::default(); | ||
for c in f.chars() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would implement FromStr
for RegexFlags
, and use the version of parse_regex_flags()
in the lexer, which iterates through bytes instead of characters, and should therefore be more efficient. Would also reduce duplicate code.
boa/src/builtins/regexp/mod.rs
Outdated
'i' => regexp.ignore_case, | ||
'u' => regexp.unicode, | ||
'y' => regexp.sticky, | ||
'g' => regexp.flags.contains(RegExpFlags::GLOBAL), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we match bytes instead of characters here? Should be more efficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my last commit the code matches on bytes, but this could be replaced with the RegExpFlags
which would allow for the following reduction in matching code:
fn regexp_has_flag(this: &JsValue, flag: RegExpFlags, context: &mut Context) -> JsResult<JsValue> {
if let Some(object) = this.as_object() {
if let Some(regexp) = object.borrow().as_regexp() {
return Ok(JsValue::new(regexp.flags.contains(flag)));
}
// ...
}
// ...
}
Which would be more readable?
const STICKY = 0b0010_0000; | ||
} | ||
} | ||
|
||
fn parse_regex_flags(s: &str, start: Position, interner: &mut Interner) -> Result<Sym, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this function together with the structure, and change it so that this implements the FromStr
trait for the structure.
Don't agree with moving the struct and accompanying functions from its original place. |
Well, ideally this structure would ideally be part of regress. But I see what you mean. Maybe it should stay in the lexer. |
I reworked the PR with the provided feedback. Feel free to leave new suggestions :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This just needs running cargo fit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
This Pull Request fixes/closes #1819. It changes the following: - Move the bitflags from `boa/src/syntax/lexer/regex.rs` to `boa/src/builtins/regexp/mod.rs` - Replace the booleans in the RegExp struct to include the bitflags struct - Update match expressions to make use of the bitflags struct Co-authored-by: Aäron Munsters <[email protected]>
Pull request successfully merged into main. Build succeeded: |
This Pull Request fixes/closes #1819.
It changes the following:
boa/src/syntax/lexer/regex.rs
toboa/src/builtins/regexp/mod.rs