Issue #28727: Optimize pattern_richcompare() for a==a
A pattern is equal to itself.
This commit is contained in:
parent
e670b2d5c3
commit
bcf4dccfa7
|
@ -1781,6 +1781,10 @@ SUBPATTERN None 0 0
|
||||||
def test_pattern_compare(self):
|
def test_pattern_compare(self):
|
||||||
pattern1 = re.compile('abc', re.IGNORECASE)
|
pattern1 = re.compile('abc', re.IGNORECASE)
|
||||||
|
|
||||||
|
# equal to itself
|
||||||
|
self.assertEqual(pattern1, pattern1)
|
||||||
|
self.assertFalse(pattern1 != pattern1)
|
||||||
|
|
||||||
# equal
|
# equal
|
||||||
re.purge()
|
re.purge()
|
||||||
pattern2 = re.compile('abc', re.IGNORECASE)
|
pattern2 = re.compile('abc', re.IGNORECASE)
|
||||||
|
|
|
@ -2683,6 +2683,12 @@ pattern_richcompare(PyObject *lefto, PyObject *righto, int op)
|
||||||
if (Py_TYPE(lefto) != &Pattern_Type || Py_TYPE(righto) != &Pattern_Type) {
|
if (Py_TYPE(lefto) != &Pattern_Type || Py_TYPE(righto) != &Pattern_Type) {
|
||||||
Py_RETURN_NOTIMPLEMENTED;
|
Py_RETURN_NOTIMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lefto == righto) {
|
||||||
|
/* a pattern is equal to itself */
|
||||||
|
return PyBool_FromLong(op == Py_EQ);
|
||||||
|
}
|
||||||
|
|
||||||
left = (PatternObject *)lefto;
|
left = (PatternObject *)lefto;
|
||||||
right = (PatternObject *)righto;
|
right = (PatternObject *)righto;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue