Commit 15d5f621 authored by Stefan Behnel's avatar Stefan Behnel

optimise dict.clear()

--HG--
extra : rebase_source : afba300a108428a9e515a63a822d62cced8e2e05
parent 446afdb8
...@@ -240,6 +240,15 @@ static PyObject* __Pyx_Intern(PyObject* s) { ...@@ -240,6 +240,15 @@ static PyObject* __Pyx_Intern(PyObject* s) {
} }
''') ''')
py_dict_clear_utility_code = UtilityCode(
proto = '''
static CYTHON_INLINE PyObject* __Pyx_PyDict_Clear(PyObject* d) {
PyDict_Clear(d);
Py_INCREF(Py_None);
return Py_None;
}
''')
py_set_utility_code = UtilityCode( py_set_utility_code = UtilityCode(
proto = """ proto = """
#if PY_VERSION_HEX < 0x02050000 #if PY_VERSION_HEX < 0x02050000
...@@ -495,6 +504,8 @@ builtin_types_table = [ ...@@ -495,6 +504,8 @@ builtin_types_table = [
("dict", "PyDict_Type", [BuiltinMethod("items", "T", "O", "PyDict_Items"), # FIXME: Py3 mode? ("dict", "PyDict_Type", [BuiltinMethod("items", "T", "O", "PyDict_Items"), # FIXME: Py3 mode?
BuiltinMethod("keys", "T", "O", "PyDict_Keys"), # FIXME: Py3 mode? BuiltinMethod("keys", "T", "O", "PyDict_Keys"), # FIXME: Py3 mode?
BuiltinMethod("values","T", "O", "PyDict_Values"), # FIXME: Py3 mode? BuiltinMethod("values","T", "O", "PyDict_Values"), # FIXME: Py3 mode?
BuiltinMethod("clear", "T", "O", "__Pyx_PyDict_Clear",
utility_code = py_dict_clear_utility_code),
BuiltinMethod("copy", "T", "T", "PyDict_Copy")]), BuiltinMethod("copy", "T", "T", "PyDict_Copy")]),
("slice", "PySlice_Type", [BuiltinAttribute('start'), ("slice", "PySlice_Type", [BuiltinAttribute('start'),
......
...@@ -87,3 +87,11 @@ def set_add(set s): ...@@ -87,3 +87,11 @@ def set_add(set s):
""" """
s.add(1) s.add(1)
return s.add(2) return s.add(2)
def dict_clear(dict d):
"""
>>> dict_clear({1:2,3:4}) is None
True
"""
d.clear()
return d.clear()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment