Changes between Initial Version and Version 1 of Ticket #24741, comment 24


Ignore:
Timestamp:
03/01/19 13:15:37 (13 months ago)
Author:
embray
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24741, comment 24

    initial v1  
    1717}}}
    1818
    19 You can also see in the [https://github.com/python/cpython/blob/master/Objects/listobject.c#L872 list.extend] implementation that it has a more optimized code path for the case where it's given a list or tuple and can use the `PySequence_Fast` API, as opposed to the more generic path of having to guess what the new size of the list will be (using `__length_hint__` if there is one) and slowly iterate over the iterable.
     19You can also see in the [https://github.com/python/cpython/blob/69b4a17f342146d6b7a73975a37678db9916aa75/Objects/listobject.c#L799 list.extend] implementation that it has a more optimized code path for the case where it's given a list or tuple and can use the `PySequence_Fast` API, as opposed to the more generic path of having to guess what the new size of the list will be (using `__length_hint__` if there is one) and slowly iterate over the iterable.
    2020
    2121Of course that's all implementation detail and there's no guarantee in the language that this should be faster.  By rights the iterator expression should be "better" but in practice it isn't, at least for small lists.