Skip to content
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

Improve RegExp comparisons #76

Merged
merged 2 commits into from
Apr 29, 2022
Merged

Conversation

planttheidea
Copy link
Owner

Reason for change

The method used for comparing RegExp values is robust, but not as fast as it could be because it does not use the flags property when supported in new environments. As such, it also does not technically support newer flags.

Change

Use the flags property when supported, else fall back to the original implementation.

@planttheidea planttheidea merged commit d3085e0 into master Apr 29, 2022
@planttheidea planttheidea deleted the improve-regexp-comparison branch April 29, 2022 13:59
export const areRegExpsEqual = (() => {
if (/foo/g.flags === 'g') {
return function areRegExpsEqual(a: RegExp, b: RegExp) {
return a.source === b.source && a.flags === b.flags;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the flags be in a different order? 'gm' vs 'mg'

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the description in MDN, which is based on the spec, the flags are ordered alphabetically. Are you seeing different results?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I was just wondering. Sorry for the noise

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants