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
eed01890
Commit
eed01890
authored
Apr 26, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Append optimization.
parent
c37a4543
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
0 deletions
+69
-0
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+3
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+27
-0
tests/run/append.pyx
tests/run/append.pyx
+39
-0
No files found.
Cython/Compiler/Builtin.py
View file @
eed01890
...
@@ -52,6 +52,9 @@ builtin_function_table = [
...
@@ -52,6 +52,9 @@ builtin_function_table = [
# Can't do these easily until we have builtin type entries.
# Can't do these easily until we have builtin type entries.
#('typecheck', "OO", "i", "PyObject_TypeCheck", False),
#('typecheck', "OO", "i", "PyObject_TypeCheck", False),
#('issubtype', "OO", "i", "PyType_IsSubtype", False),
#('issubtype', "OO", "i", "PyType_IsSubtype", False),
# Put in namespace append optimization.
(
'__Pyx_PyObject_Append'
,
"OO"
,
"O"
,
"__Pyx_PyObject_Append"
),
]
]
# Builtin types
# Builtin types
...
...
Cython/Compiler/ExprNodes.py
View file @
eed01890
...
@@ -1519,12 +1519,15 @@ class SimpleCallNode(ExprNode):
...
@@ -1519,12 +1519,15 @@ class SimpleCallNode(ExprNode):
# coerced_self ExprNode or None used internally
# coerced_self ExprNode or None used internally
# wrapper_call bool used internally
# wrapper_call bool used internally
# optimized_call str or None
subexprs
=
[
'self'
,
'coerced_self'
,
'function'
,
'args'
,
'arg_tuple'
]
subexprs
=
[
'self'
,
'coerced_self'
,
'function'
,
'args'
,
'arg_tuple'
]
self
=
None
self
=
None
coerced_self
=
None
coerced_self
=
None
arg_tuple
=
None
arg_tuple
=
None
wrapper_call
=
False
wrapper_call
=
False
optimized_call
=
None
def
compile_time_value
(
self
,
denv
):
def
compile_time_value
(
self
,
denv
):
function
=
self
.
function
.
compile_time_value
(
denv
)
function
=
self
.
function
.
compile_time_value
(
denv
)
...
@@ -1538,6 +1541,15 @@ class SimpleCallNode(ExprNode):
...
@@ -1538,6 +1541,15 @@ class SimpleCallNode(ExprNode):
function
=
self
.
function
function
=
self
.
function
function
.
is_called
=
1
function
.
is_called
=
1
self
.
function
.
analyse_types
(
env
)
self
.
function
.
analyse_types
(
env
)
if
function
.
is_attribute
and
function
.
is_py_attr
and
\
function
.
attribute
==
"append"
and
len
(
self
.
args
)
==
1
:
# L.append(x) is almost always applied to a list
self
.
py_func
=
self
.
function
self
.
function
=
NameNode
(
pos
=
self
.
function
.
pos
,
name
=
"__Pyx_PyObject_Append"
)
self
.
function
.
analyse_types
(
env
)
self
.
self
=
self
.
py_func
.
obj
function
.
obj
=
CloneNode
(
self
.
self
)
env
.
use_utility_code
(
append_utility_code
)
if
function
.
is_attribute
and
function
.
entry
and
function
.
entry
.
is_cmethod
:
if
function
.
is_attribute
and
function
.
entry
and
function
.
entry
.
is_cmethod
:
# Take ownership of the object from which the attribute
# Take ownership of the object from which the attribute
# was obtained, because we need to pass it as 'self'.
# was obtained, because we need to pass it as 'self'.
...
@@ -4105,3 +4117,18 @@ static void __Pyx_CppExn2PyErr() {
...
@@ -4105,3 +4117,18 @@ static void __Pyx_CppExn2PyErr() {
"""
,
""
]
"""
,
""
]
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
append_utility_code
=
[
"""
static inline PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
if (likely(PyList_CheckExact(L))) {
if (PyList_Append(L, x) < 0) return NULL;
Py_INCREF(Py_None);
return Py_None; // this is just to have an accurate signature
}
else {
return PyObject_CallMethod(L, "append", "O", x);
}
}
"""
,
""
]
\ No newline at end of file
tests/run/append.pyx
0 → 100644
View file @
eed01890
__doc__
=
"""
>>> test_append([])
None
None
got error
[1, 2]
>>> test_append(A())
appending
1
appending
2
got error
<append.A instance at ...>
>>> test_append(B())
None
None
None
[1, 2, 3, 4]
"""
class
A
:
def
append
(
self
,
x
):
print
"appending"
return
x
class
B
(
list
):
def
append
(
self
,
*
args
):
for
arg
in
args
:
list
.
append
(
self
,
arg
)
def
test_append
(
L
):
print
L
.
append
(
1
)
print
L
.
append
(
2
)
try
:
print
L
.
append
(
3
,
4
)
except
TypeError
:
print
"got error"
print
L
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