mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Expose dict_contains() and PyDict_Contains() with is about 10% faster
than PySequence_Contains() and more clearly applicable to dicts. Apply the new function in setobject.c where __contains__ checking is ubiquitous.
This commit is contained in:
parent
3972457de7
commit
bc0f2ab9bb
5 changed files with 26 additions and 12 deletions
|
@ -1814,10 +1814,11 @@ static PyMethodDef mapp_methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static int
|
||||
dict_contains(dictobject *mp, PyObject *key)
|
||||
int
|
||||
PyDict_Contains(PyObject *op, PyObject *key)
|
||||
{
|
||||
long hash;
|
||||
dictobject *mp = (dictobject *)op;
|
||||
|
||||
if (!PyString_CheckExact(key) ||
|
||||
(hash = ((PyStringObject *) key)->ob_shash) == -1) {
|
||||
|
@ -1837,7 +1838,7 @@ static PySequenceMethods dict_as_sequence = {
|
|||
0, /* sq_slice */
|
||||
0, /* sq_ass_item */
|
||||
0, /* sq_ass_slice */
|
||||
(objobjproc)dict_contains, /* sq_contains */
|
||||
(objobjproc)PyDict_Contains, /* sq_contains */
|
||||
0, /* sq_inplace_concat */
|
||||
0, /* sq_inplace_repeat */
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue