forked from greasemonkey/greasemonkey
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The RegExp object - small performance improvements
- Loading branch information
1 parent
90b9579
commit 9608b0d
Showing
7 changed files
with
22 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9608b0d
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.
If you want regex performance improvements, then don't use String.prototype.match() for the if statements here. Instead use RegExp.prototype.test() or even String.prototype.search(). E.g., instead of doing " if (url.match(_re)) { " do " if (_re.test(url)) { " or " if (url.search(_re) !== -1) { ". Do note that RegExp.prototype.test() is not a drop in replacement, as it has the behavior that using it will not reset the lastIndex property, so subsequent calls may not give the result that was expected.
I suggest replacing String.prototype.match() inside of if statements with String.prototype.search() as it will work fine as a drop in replacement for if statements, and will give a much better performance improvement than what you have already done here.
9608b0d
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.
Thank you. But I will not change it now. Maybe in the future.
But I know sites like https://jsperf.com/ etc.
Changes were only symbolic - high performance is not needed.
But in some cases it makes sense, e.g.
greasemonkey#2318