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
Gwenaël Samain
cython
Commits
93440ae2
Commit
93440ae2
authored
Sep 10, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid calling PySequence_Tuple() if what we have is exactly a tuple.
parent
51a20816
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
11 deletions
+9
-11
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-3
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+2
-8
Cython/Utility/TypeConversion.c
Cython/Utility/TypeConversion.c
+3
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
93440ae2
...
@@ -6264,6 +6264,7 @@ class AsTupleNode(ExprNode):
...
@@ -6264,6 +6264,7 @@ class AsTupleNode(ExprNode):
# arg ExprNode
# arg ExprNode
subexprs
=
[
'arg'
]
subexprs
=
[
'arg'
]
is_temp
=
1
def
calculate_constant_result
(
self
):
def
calculate_constant_result
(
self
):
self
.
constant_result
=
tuple
(
self
.
arg
.
constant_result
)
self
.
constant_result
=
tuple
(
self
.
arg
.
constant_result
)
...
@@ -6280,7 +6281,6 @@ class AsTupleNode(ExprNode):
...
@@ -6280,7 +6281,6 @@ class AsTupleNode(ExprNode):
if
self
.
arg
.
type
is
tuple_type
:
if
self
.
arg
.
type
is
tuple_type
:
return
self
.
arg
.
as_none_safe_node
(
"'NoneType' object is not iterable"
)
return
self
.
arg
.
as_none_safe_node
(
"'NoneType' object is not iterable"
)
self
.
type
=
tuple_type
self
.
type
=
tuple_type
self
.
is_temp
=
1
return
self
return
self
def
may_be_none
(
self
):
def
may_be_none
(
self
):
...
@@ -6290,10 +6290,11 @@ class AsTupleNode(ExprNode):
...
@@ -6290,10 +6290,11 @@ class AsTupleNode(ExprNode):
gil_message
=
"Constructing Python tuple"
gil_message
=
"Constructing Python tuple"
def
generate_result_code
(
self
,
code
):
def
generate_result_code
(
self
,
code
):
cfunc
=
"__Pyx_PySequence_Tuple"
if
self
.
arg
.
type
in
(
py_object_type
,
tuple_type
)
else
"PySequence_Tuple"
code
.
putln
(
code
.
putln
(
"%s =
PySequence_Tuple
(%s); %s"
%
(
"%s =
%s
(%s); %s"
%
(
self
.
result
(),
self
.
result
(),
self
.
arg
.
py_result
(),
cfunc
,
self
.
arg
.
py_result
(),
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
py_result
())
code
.
put_gotref
(
self
.
py_result
())
...
...
Cython/Compiler/Optimize.py
View file @
93440ae2
...
@@ -2210,14 +2210,10 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
...
@@ -2210,14 +2210,10 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
PyrexTypes
.
CFuncTypeArg
(
"list"
,
Builtin
.
list_type
,
None
)
PyrexTypes
.
CFuncTypeArg
(
"list"
,
Builtin
.
list_type
,
None
)
])
])
PySequence_Tuple_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
tuple_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"it"
,
PyrexTypes
.
py_object_type
,
None
)])
def
_handle_simple_function_tuple
(
self
,
node
,
function
,
pos_args
):
def
_handle_simple_function_tuple
(
self
,
node
,
function
,
pos_args
):
"""Replace tuple([...]) by PyList_AsTuple or PySequence_Tuple.
"""Replace tuple([...]) by PyList_AsTuple or PySequence_Tuple.
"""
"""
if
len
(
pos_args
)
!=
1
:
if
len
(
pos_args
)
!=
1
or
not
node
.
is_temp
:
return
node
return
node
arg
=
pos_args
[
0
]
arg
=
pos_args
[
0
]
if
arg
.
type
is
Builtin
.
tuple_type
and
not
arg
.
may_be_none
():
if
arg
.
type
is
Builtin
.
tuple_type
and
not
arg
.
may_be_none
():
...
@@ -2230,9 +2226,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
...
@@ -2230,9 +2226,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
node
.
pos
,
"PyList_AsTuple"
,
self
.
PyList_AsTuple_func_type
,
node
.
pos
,
"PyList_AsTuple"
,
self
.
PyList_AsTuple_func_type
,
args
=
pos_args
,
is_temp
=
node
.
is_temp
)
args
=
pos_args
,
is_temp
=
node
.
is_temp
)
else
:
else
:
return
ExprNodes
.
PythonCapiCallNode
(
return
ExprNodes
.
AsTupleNode
(
node
.
pos
,
arg
=
arg
,
type
=
Builtin
.
tuple_type
)
node
.
pos
,
"PySequence_Tuple"
,
self
.
PySequence_Tuple_func_type
,
args
=
pos_args
,
is_temp
=
node
.
is_temp
)
PySet_New_func_type
=
PyrexTypes
.
CFuncType
(
PySet_New_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
set_type
,
[
Builtin
.
set_type
,
[
...
...
Cython/Utility/TypeConversion.c
View file @
93440ae2
...
@@ -92,6 +92,9 @@ static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
...
@@ -92,6 +92,9 @@ static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
static
CYTHON_INLINE
int
__Pyx_PyObject_IsTrue
(
PyObject
*
);
static
CYTHON_INLINE
int
__Pyx_PyObject_IsTrue
(
PyObject
*
);
static
CYTHON_INLINE
PyObject
*
__Pyx_PyNumber_IntOrLong
(
PyObject
*
x
);
static
CYTHON_INLINE
PyObject
*
__Pyx_PyNumber_IntOrLong
(
PyObject
*
x
);
#define __Pyx_PySequence_Tuple(obj) \
(likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static
CYTHON_INLINE
Py_ssize_t
__Pyx_PyIndex_AsSsize_t
(
PyObject
*
);
static
CYTHON_INLINE
Py_ssize_t
__Pyx_PyIndex_AsSsize_t
(
PyObject
*
);
static
CYTHON_INLINE
PyObject
*
__Pyx_PyInt_FromSize_t
(
size_t
);
static
CYTHON_INLINE
PyObject
*
__Pyx_PyInt_FromSize_t
(
size_t
);
...
...
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