Commit 9ba3f98b authored by Stefan Behnel's avatar Stefan Behnel

optimise set.update()

parent 3c9e7f25
......@@ -319,6 +319,8 @@ builtin_types_table = [
BuiltinMethod("clear", "T", "r", "PySet_Clear"),
# discard() and remove() have a special treatment for unhashable values
# BuiltinMethod("discard", "TO", "r", "PySet_Discard"),
BuiltinMethod("update", "TO", "r", "__Pyx_PySet_Update",
utility_code=UtilityCode.load_cached("PySet_Update", "Builtins.c")),
BuiltinMethod("add", "TO", "r", "PySet_Add"),
BuiltinMethod("pop", "T", "O", "PySet_Pop")]),
("frozenset", "PyFrozenSet_Type", []),
......
......@@ -71,6 +71,52 @@ def test_set_add():
return s1
def test_set_update(v=None):
"""
>>> type(test_set_update()) is _set
True
>>> sorted(test_set_update())
['a', 'b', 'c', 1, 2, (1, 2)]
>>> sorted(test_set_update([]))
['a', 'b', 'c', 1, 2, (1, 2)]
>>> try: test_set_update(object())
... except TypeError: pass
... else: print("NOT RAISED!")
"""
cdef set s1
s1 = set([1, (1, 2)])
s1.update((1,))
s1.update('abc')
s1.update(set([1]))
s1.update(frozenset((1,2)))
if v is not None:
s1.update(v)
return s1
def test_object_update(v=None):
"""
>>> type(test_object_update()) is _set
True
>>> sorted(test_object_update())
['a', 'b', 'c', 1, 2, (1, 2)]
>>> sorted(test_object_update([]))
['a', 'b', 'c', 1, 2, (1, 2)]
>>> try: test_object_update(object())
... except TypeError: pass
... else: print("NOT RAISED!")
"""
cdef object s1
s1 = set([1, (1, 2)])
s1.update((1,))
s1.update('abc')
s1.update(set([1]))
s1.update(frozenset((1,2)))
if v is not None:
s1.update(v)
return s1
def test_set_clear():
"""
>>> type(test_set_clear()) is _set
......
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