[issue26077] Make slicing of immutable structures return a view instead of a copy

2016-01-16 Thread Terry J. Reedy
Terry J. Reedy added the comment: Proposals for strings views have be rejected precisely because of the keep-alive effect. I do not remember if tuples were explicitly part of earlier discussions. One could make the argument that million-item tuples, and especially slicing thereof is rarer

[issue26077] Make slicing of immutable structures return a view instead of a copy

2016-01-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The support of sharing a content between different tuples requires changing the structure of the tuple object, allocating additional block for every tuple, adding a level of indirection and reference counting. This will increase memory consumption, creating

[issue26077] Make slicing of immutable structures return a view instead of a copy

2016-01-10 Thread Filip Haglund
New submission from Filip Haglund: Slicing tuples returns a copy, which is O(n) time. This could be O(1) since tuples are immutable, by just pointing to the same data. This probably applies to other immutable structures as well, such as strings. -- components: Interpreter Core

[issue26077] Make slicing of immutable structures return a view instead of a copy

2016-01-10 Thread Emanuel Barry
Emanuel Barry added the comment: This is an interesting idea, +1 from me. Do you want to submit a patch? -- nosy: +ebarry stage: -> needs patch versions: -Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5 ___ Python tracker

[issue26077] Make slicing of immutable structures return a view instead of a copy

2016-01-10 Thread Martin Panter
Martin Panter added the comment: I think which technique (copy or view) is better depends on the situation. If you are making a large temporary slice, a view may be more efficient. But if you are making a long-term slice and don’t need the original any more, a copy would allow the original