Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
cython
Commits
66221af5
Commit
66221af5
authored
7 years ago
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize `x in set` using PySet_Contains()
parent
757c030e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+5
-0
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+26
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
66221af5
...
...
@@ -12197,6 +12197,11 @@ class CmpNode(object):
self
.
special_bool_cmp_utility_code
=
UtilityCode
.
load_cached
(
"PyDictContains"
,
"ObjectHandling.c"
)
self
.
special_bool_cmp_function
=
"__Pyx_PyDict_ContainsTF"
return
True
elif
self
.
operand2
.
type
is
Builtin
.
set_type
:
self
.
operand2
=
self
.
operand2
.
as_none_safe_node
(
"'NoneType' object is not iterable"
)
self
.
special_bool_cmp_utility_code
=
UtilityCode
.
load_cached
(
"PySetContains"
,
"ObjectHandling.c"
)
self
.
special_bool_cmp_function
=
"__Pyx_PySet_ContainsTF"
return
True
elif
self
.
operand2
.
type
is
Builtin
.
unicode_type
:
self
.
operand2
=
self
.
operand2
.
as_none_safe_node
(
"'NoneType' object is not iterable"
)
self
.
special_bool_cmp_utility_code
=
UtilityCode
.
load_cached
(
"PyUnicodeContains"
,
"StringTools.c"
)
...
...
This diff is collapsed.
Click to expand it.
Cython/Utility/ObjectHandling.c
View file @
66221af5
...
...
@@ -1035,6 +1035,32 @@ static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict,
return
unlikely
(
result
<
0
)
?
result
:
(
result
==
(
eq
==
Py_EQ
));
}
/////////////// PySetContains.proto ///////////////
static
int
__Pyx_PySet_ContainsUnhashable
(
PyObject
*
set
,
PyObject
*
key
)
{
int
result
=
-
1
;
if
(
PySet_Check
(
key
)
&&
PyErr_ExceptionMatches
(
PyExc_TypeError
))
{
/* Convert key to frozenset */
PyObject
*
tmpkey
;
PyErr_Clear
();
tmpkey
=
PyFrozenSet_New
(
key
);
if
(
tmpkey
!=
NULL
)
{
result
=
PySet_Contains
(
set
,
tmpkey
);
Py_DECREF
(
tmpkey
);
}
}
return
result
;
}
static
CYTHON_INLINE
int
__Pyx_PySet_ContainsTF
(
PyObject
*
key
,
PyObject
*
set
,
int
eq
)
{
int
result
=
PySet_Contains
(
set
,
key
);
if
(
unlikely
(
result
<
0
))
{
result
=
__Pyx_PySet_ContainsUnhashable
(
set
,
key
);
}
return
unlikely
(
result
<
0
)
?
result
:
(
result
==
(
eq
==
Py_EQ
));
}
/////////////// PySequenceContains.proto ///////////////
static
CYTHON_INLINE
int
__Pyx_PySequence_ContainsTF
(
PyObject
*
item
,
PyObject
*
seq
,
int
eq
)
{
...
...
This diff is collapsed.
Click to expand it.
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