-
Notifications
You must be signed in to change notification settings - Fork 1.7k
use string equality instead of regexps to compare constant strings #9182
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
Conversation
exists(string reg | call.getMemberName() = "matches" | | ||
call.getNumberOfArguments() = 1 and | ||
reg = call.getArgument(0).(String).getValue() and | ||
not reg.regexpMatch(".*%.*") |
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.
Underscore is also special in match strings and it matches any character. However I also note that most cases with underscores seem to be bugs where an escaped underscore is intended.
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.
However I also note that most cases with underscores seem to be bugs where an escaped underscore is intended.
I found two uses of underscores, both were bugs.
I've fixed them.
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.
C# and Ruby 👍
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.
Java LGTM
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.
C++ 👍
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.
JS 👍🏻
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.
Python/QL 👍
Regexps have previously been used to encode a set of strings, but now that we have set literals we should use those instead.
And sometimes regexps seem to be used without any good reason (second example below).
Consider the below examples.
Rewriting from a regular expression to comparison against string constants means that there are more possible join-orders for the optimizer to choose from, so we need to run performance evaluations.
Evaluations all look good: CPP, C#, JavaScript, Java, Python, Ruby.
I had to do a bunch of retries in C++ before that turned out OK, but I think that's due to big variations in DB creation time
(DB caching in DCA 🙏).
Inspired by this comment: #5160 (reply in thread)