| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
| return self.primitive_op(str_eq, [lhs, rhs], line) | ||
| elif op == "!=": | ||
| eq = self.primitive_op(str_eq, [lhs, rhs], line) | ||
| if is_string_literal(lhs): |
There was a problem hiding this comment.
looking at this again, I think we can just refactor this whole block for "!=" into:
return self.add(ComparisonOp(compare_strings(lhs, rhs, line), self.false(), ComparisonOp.EQ, line)
Sorry, something went wrong.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
| Py_ssize_t str1_length = PyUnicode_GET_LENGTH(str1); | ||
| if (str1_length != str2_length) | ||
| return 0; | ||
| int kind = PyUnicode_KIND(str1); |
There was a problem hiding this comment.
Can we deduce a literal's kind at compile time as well?
Sorry, something went wrong.
There was a problem hiding this comment.
Looks like there isn't a good way to reliably do this
Sorry, something went wrong.
| if is_string_literal(lhs): | ||
| if is_string_literal(rhs): | ||
| # we can optimize out the check entirely in some constant-folded cases | ||
| return self.true() if lhs.value == rhs.value else self.false() |
There was a problem hiding this comment.
Add a irbuild test cases for constant folding.
Sorry, something went wrong.
| return self.true() if lhs.value == rhs.value else self.false() | ||
|
|
||
| # if lhs argument is string literal, switch sides to match specializer C api | ||
| lhs, rhs = rhs, lhs |
There was a problem hiding this comment.
Add irbuild test case for string literal as the lhs.
Sorry, something went wrong.
There was a problem hiding this comment.
Added both
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR further optimizes string equality checks against literals by getting rid of the PyUnicode_GET_LENGTH call against the literal value, which is not necessary since the value is known at compile-time
I think this optimization will be helpful in cases where the non-literal string DOES match but is actually a subtype of string (actual strings instances that match would be caught by the identity check), or in cases where an exact string does NOT match. But we can also extend this implementation to use c-strings in certain cases where we know at compile-time that the literal value is compact ascii. Actually, maybe I should do that now? Thoughts?