Thomas Wouters <thomas@xs4all.net>:

The following patch adds "sq_contains" support to rangeobject, and enables
the already-written support for sq_contains in listobject and tupleobject.

The rangeobject "contains" code should be a bit more efficient than the
current default "in" implementation ;-) It might not get used much, but it's
not that much to add.

listobject.c and tupleobject.c already had code for sq_contains, and the
proper struct member was set, but the PyType structure was not extended to
include tp_flags, so the object-specific code was not getting called (Go
ahead, test it ;-). I also did this for the immutable_list_type in
listobject.c, eventhough it is probably never used. Symmetry and all that.
This commit is contained in:
Fred Drake 2000-06-15 14:50:20 +00:00
parent 60bc809d9a
commit 56780257c6
3 changed files with 46 additions and 0 deletions

View file

@ -1489,6 +1489,13 @@ PyTypeObject PyList_Type = {
0, /*tp_as_number*/
&list_as_sequence, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
};
@ -1540,6 +1547,7 @@ static PySequenceMethods immutable_list_as_sequence = {
(intintargfunc)list_slice, /*sq_slice*/
(intobjargproc)immutable_list_ass, /*sq_ass_item*/
(intintobjargproc)immutable_list_ass, /*sq_ass_slice*/
(objobjproc)list_contains, /*sq_contains*/
};
static PyTypeObject immutable_list_type = {
@ -1557,5 +1565,12 @@ static PyTypeObject immutable_list_type = {
0, /*tp_as_number*/
&immutable_list_as_sequence, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
};