]> granicus.if.org Git - python/commit
Refactor list_extend() and list_fill() for gains in code size, memory
authorRaymond Hettinger <python@rcn.com>
Sun, 15 Feb 2004 03:57:00 +0000 (03:57 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 15 Feb 2004 03:57:00 +0000 (03:57 +0000)
commit90a39bf12c96c47a45c9b7ce3b10f3a3817bd5ac
tree7ee5f0c729e788c8741a63770ba1a34d50f344d2
parentab517d2eacba7fec5f31dd25b8e43dca678cda53
Refactor list_extend() and list_fill() for gains in code size, memory
utilization, and speed:

* Moved the responsibility for emptying the previous list from list_fill
  to list_init.

* Replaced the code in list_extend with the superior code from list_fill.

* Eliminated list_fill.

Results:

* list.extend() no longer creates an intermediate tuple except to handle
  the special case of x.extend(x).  The saves memory and time.

* list.extend(x) runs
    5 to 10% faster when x is a list or tuple
    15% faster when x is an iterable not defining __len__
    twice as fast when x is an iterable defining __len__

* the code is about 15 lines shorter and no longer duplicates
  functionality.
Objects/listobject.c