Kaydet (Commit) 9c1491f3 authored tarafından Raymond Hettinger's avatar Raymond Hettinger

* Add a fast equality check path for frozensets where the hash value has

  already been computed.
* Apply a GET_SIZE macro().
üst 26292a3a
...@@ -1495,12 +1495,15 @@ set_richcompare(PySetObject *v, PyObject *w, int op) ...@@ -1495,12 +1495,15 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
case Py_EQ: case Py_EQ:
if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w)) if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w))
Py_RETURN_FALSE; Py_RETURN_FALSE;
if (v->hash != -1 &&
((PySetObject *)w)->hash != -1 &&
v->hash != ((PySetObject *)w)->hash)
Py_RETURN_FALSE;
return set_issubset(v, w); return set_issubset(v, w);
case Py_NE: case Py_NE:
if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w)) r1 = set_richcompare(v, w, Py_EQ);
Py_RETURN_TRUE; if (r1 == NULL)
r1 = set_issubset(v, w); return NULL;
assert (r1 != NULL);
r2 = PyBool_FromLong(PyObject_Not(r1)); r2 = PyBool_FromLong(PyObject_Not(r1));
Py_DECREF(r1); Py_DECREF(r1);
return r2; return r2;
...@@ -1956,7 +1959,7 @@ PySet_Size(PyObject *anyset) ...@@ -1956,7 +1959,7 @@ PySet_Size(PyObject *anyset)
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return -1; return -1;
} }
return ((PySetObject *)anyset)->used; return PySet_GET_SIZE(anyset);
} }
int int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment