mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-141367: Use CALL_LIST_APPEND instruction only for lists, not for list subclasses (GH-141398)
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
This commit is contained in:
parent
f26ed455d5
commit
1281be1caf
7 changed files with 44 additions and 20 deletions
|
|
@ -1872,6 +1872,33 @@ def for_iter_generator():
|
|||
self.assert_specialized(for_iter_generator, "FOR_ITER_GEN")
|
||||
self.assert_no_opcode(for_iter_generator, "FOR_ITER")
|
||||
|
||||
@cpython_only
|
||||
@requires_specialization_ft
|
||||
def test_call_list_append(self):
|
||||
# gh-141367: only exact lists should use
|
||||
# CALL_LIST_APPEND instruction after specialization.
|
||||
|
||||
r = range(_testinternalcapi.SPECIALIZATION_THRESHOLD)
|
||||
|
||||
def list_append(l):
|
||||
for _ in r:
|
||||
l.append(1)
|
||||
|
||||
list_append([])
|
||||
self.assert_specialized(list_append, "CALL_LIST_APPEND")
|
||||
self.assert_no_opcode(list_append, "CALL_METHOD_DESCRIPTOR_O")
|
||||
self.assert_no_opcode(list_append, "CALL")
|
||||
|
||||
def my_list_append(l):
|
||||
for _ in r:
|
||||
l.append(1)
|
||||
|
||||
class MyList(list): pass
|
||||
my_list_append(MyList())
|
||||
self.assert_specialized(my_list_append, "CALL_METHOD_DESCRIPTOR_O")
|
||||
self.assert_no_opcode(my_list_append, "CALL_LIST_APPEND")
|
||||
self.assert_no_opcode(my_list_append, "CALL")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue