diff options
author | Raymond Hettinger <python@rcn.com> | 2003-11-25 21:12:14 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-11-25 21:12:14 (GMT) |
commit | bc0f2ab9bbe1380a32cc63823258a337a525fb32 (patch) | |
tree | 4e0f76ebe43b74cab10b1e6bd41b1d90fe6f8230 /Objects/dictobject.c | |
parent | 3972457de72fa6d95d94df14a3bb402798aa092c (diff) | |
download | cpython-bc0f2ab9bbe1380a32cc63823258a337a525fb32.zip cpython-bc0f2ab9bbe1380a32cc63823258a337a525fb32.tar.gz cpython-bc0f2ab9bbe1380a32cc63823258a337a525fb32.tar.bz2 |
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.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 5d22404..0cf71b5 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -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 */ }; |