Skip to content

Improved solution to issue #179 (invalid options throwing errors in joinRegExp) #180

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
merged 3 commits into from
Jan 12, 2014

Conversation

johnbacon
Copy link
Contributor

This slightly more robust solution ignores options that are not strings
or regular expressions in the passed patterns array.

The prior solution still accepted non-string, non-regexp options (e.g.
[], {}, true, etc.).

Credit goes to @soundslocke for the fix.

…rors in joinRegExp)

This slightly more robust solution ignores options that are not strings
or regular expressions in the passed patterns array.

The prior solution still accepted non-string, non-regexp options (e.g.
[], {}, true, etc.).

Credit goes to @soundslocke for the fix.
// If it's a string, we need to escape it
// Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
sources.unshift(patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"));
} else if (!isUndefined(patterns[i]) && patterns[i] && patterns[i].source) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to check again for isUndefined? Wouldn't just patterns[i] && patterns[i].source be enough?

@mattrobenolt
Copy link
Contributor

unshift is also pretty terribly slow. At this point, it'd make more sense to just flip it to a normal for loop and use push. There's no point in being clever and looping in reverse now if we acknowledge that there can be gaps in the array.

@johnbacon
Copy link
Contributor Author

I have no problem moving to a normal for loop and away from unshift. As you stated, this seems to confirm there is still a significant performance difference between unshift and push.

The changes will be pushed again soon.

```unshift``` is significantly slower than ```push```. Shift towards
using ```push``` and remove a redundant conditional.
Likely
[benefits](http://stackoverflow.com/questions/6261953/do-modern-javascript-jiters-need-array-length-caching-in-loops)
the performance of older browsers that lack smart caching.

Thanks again to @soundslocke for the heads up.
@mattrobenolt
Copy link
Contributor

This looks sensible to me. Thanks for the contribution! 👍

I'll cut a new release today.

mattrobenolt added a commit that referenced this pull request Jan 12, 2014
Improved solution to issue #179 (invalid options throwing errors in joinRegExp)
@mattrobenolt mattrobenolt merged commit f3baeee into getsentry:master Jan 12, 2014
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