Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8fd96b97
Commit
8fd96b97
authored
Apr 27, 2000
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add list_contains and tuplecontains: efficient implementations of tp_contains
parent
65770d0f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
Objects/listobject.c
Objects/listobject.c
+21
-0
Objects/tupleobject.c
Objects/tupleobject.c
+18
-0
No files found.
Objects/listobject.c
View file @
8fd96b97
...
@@ -306,6 +306,26 @@ list_length(a)
...
@@ -306,6 +306,26 @@ list_length(a)
return
a
->
ob_size
;
return
a
->
ob_size
;
}
}
static
int
list_contains
(
a
,
el
)
PyListObject
*
a
;
PyObject
*
el
;
{
int
i
,
cmp
;
for
(
i
=
0
;
i
<
a
->
ob_size
;
++
i
)
{
cmp
=
PyObject_Compare
(
el
,
PyList_GET_ITEM
(
a
,
i
));
if
(
cmp
==
0
)
return
1
;
if
(
PyErr_Occurred
())
return
-
1
;
}
return
0
;
}
static
PyObject
*
static
PyObject
*
list_item
(
a
,
i
)
list_item
(
a
,
i
)
PyListObject
*
a
;
PyListObject
*
a
;
...
@@ -1447,6 +1467,7 @@ static PySequenceMethods list_as_sequence = {
...
@@ -1447,6 +1467,7 @@ static PySequenceMethods list_as_sequence = {
(
intintargfunc
)
list_slice
,
/*sq_slice*/
(
intintargfunc
)
list_slice
,
/*sq_slice*/
(
intobjargproc
)
list_ass_item
,
/*sq_ass_item*/
(
intobjargproc
)
list_ass_item
,
/*sq_ass_item*/
(
intintobjargproc
)
list_ass_slice
,
/*sq_ass_slice*/
(
intintobjargproc
)
list_ass_slice
,
/*sq_ass_slice*/
(
objobjproc
)
list_contains
,
/*sq_contains*/
};
};
PyTypeObject
PyList_Type
=
{
PyTypeObject
PyList_Type
=
{
...
...
Objects/tupleobject.c
View file @
8fd96b97
...
@@ -281,6 +281,23 @@ tuplelength(a)
...
@@ -281,6 +281,23 @@ tuplelength(a)
return
a
->
ob_size
;
return
a
->
ob_size
;
}
}
static
int
tuplecontains
(
a
,
el
)
PyTupleObject
*
a
;
PyObject
*
el
;
{
int
i
,
cmp
;
for
(
i
=
0
;
i
<
a
->
ob_size
;
++
i
)
{
cmp
=
PyObject_Compare
(
el
,
PyTuple_GET_ITEM
(
a
,
i
));
if
(
cmp
==
0
)
return
1
;
if
(
PyErr_Occurred
())
return
-
1
;
}
return
0
;
}
static
PyObject
*
static
PyObject
*
tupleitem
(
a
,
i
)
tupleitem
(
a
,
i
)
register
PyTupleObject
*
a
;
register
PyTupleObject
*
a
;
...
@@ -409,6 +426,7 @@ static PySequenceMethods tuple_as_sequence = {
...
@@ -409,6 +426,7 @@ static PySequenceMethods tuple_as_sequence = {
(
intintargfunc
)
tupleslice
,
/*sq_slice*/
(
intintargfunc
)
tupleslice
,
/*sq_slice*/
0
,
/*sq_ass_item*/
0
,
/*sq_ass_item*/
0
,
/*sq_ass_slice*/
0
,
/*sq_ass_slice*/
(
objobjproc
)
tuplecontains
,
/*sq_contains*/
};
};
PyTypeObject
PyTuple_Type
=
{
PyTypeObject
PyTuple_Type
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment