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
f1744511
Commit
f1744511
authored
Apr 15, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify dict.clear() optimisation
parent
ee471d52
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
33 deletions
+9
-33
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+2
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+0
-28
Cython/Utility/Optimize.c
Cython/Utility/Optimize.c
+1
-5
tests/run/builtin_methods_return_values.pyx
tests/run/builtin_methods_return_values.pyx
+6
-0
No files found.
Cython/Compiler/Builtin.py
View file @
f1744511
...
...
@@ -457,6 +457,8 @@ builtin_types_table = [
(
"dict"
,
"PyDict_Type"
,
[
BuiltinMethod
(
"items"
,
"T"
,
"O"
,
"PyDict_Items"
),
# FIXME: Py3 mode?
BuiltinMethod
(
"keys"
,
"T"
,
"O"
,
"PyDict_Keys"
),
# FIXME: Py3 mode?
BuiltinMethod
(
"values"
,
"T"
,
"O"
,
"PyDict_Values"
),
# FIXME: Py3 mode?
BuiltinMethod
(
"clear"
,
"T"
,
"r"
,
"__Pyx_PyDict_Clear"
,
utility_code
=
UtilityCode
.
load_cached
(
"py_dict_clear"
,
"Optimize.c"
)),
BuiltinMethod
(
"copy"
,
"T"
,
"T"
,
"PyDict_Copy"
)]),
(
"slice"
,
"PySlice_Type"
,
[
BuiltinAttribute
(
'start'
),
...
...
Cython/Compiler/Optimize.py
View file @
f1744511
...
...
@@ -2288,34 +2288,6 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
### methods of builtin types
PyDict_Clear_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_void_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"dict"
,
Builtin
.
dict_type
,
None
)
])
PyDict_Clear_Retval_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
py_object_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"dict"
,
Builtin
.
dict_type
,
None
)
])
def
_handle_simple_method_dict_clear
(
self
,
node
,
args
,
is_unbound_method
):
"""Optimise dict.clear() differently, depending on the use (or
non-use) of the return value.
"""
if
len
(
args
)
!=
1
:
return
node
if
node
.
result_is_used
:
return
self
.
_substitute_method_call
(
node
,
"__Pyx_PyDict_Clear"
,
self
.
PyDict_Clear_Retval_func_type
,
'clear'
,
is_unbound_method
,
args
,
may_return_none
=
True
,
is_temp
=
True
,
utility_code
=
load_c_utility
(
'py_dict_clear'
)
).
coerce_to
(
node
.
type
,
self
.
current_env
)
else
:
return
self
.
_substitute_method_call
(
node
,
"PyDict_Clear"
,
self
.
PyDict_Clear_func_type
,
'clear'
,
is_unbound_method
,
args
,
is_temp
=
False
)
PyObject_Append_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
py_object_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"list"
,
PyrexTypes
.
py_object_type
,
None
),
...
...
Cython/Utility/Optimize.c
View file @
f1744511
...
...
@@ -309,11 +309,7 @@ static PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *d
/////////////// py_dict_clear.proto ///////////////
static
CYTHON_INLINE
PyObject
*
__Pyx_PyDict_Clear
(
PyObject
*
d
)
{
PyDict_Clear
(
d
);
Py_INCREF
(
Py_None
);
return
Py_None
;
}
#define __Pyx_PyDict_Clear(d) (PyDict_Clear(d), 0)
/////////////// dict_iter.proto ///////////////
...
...
tests/run/builtin_methods_return_values.pyx
View file @
f1744511
...
...
@@ -68,6 +68,9 @@ def set_clear(set s):
"""
>>> set_clear(_set([1,2,3])) is None
True
>>> set_clear(None)
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'clear'
"""
s
.
clear
()
return
s
.
clear
()
...
...
@@ -92,6 +95,9 @@ def dict_clear(dict d):
"""
>>> dict_clear({1:2,3:4}) is None
True
>>> dict_clear(None)
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'clear'
"""
d
.
clear
()
return
d
.
clear
()
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