[New-bugs-announce] [issue1538] Avoid string copy when split char doesn't match
Skip Montanaro
report at bugs.python.org
Sun Dec 2 08:51:03 CET 2007
New submission from Skip Montanaro:
The topic of avoiding string copies in certain string methods came up in
the
ChiPy list:
http://mail.python.org/pipermail/chicago/2007-December/002975.html.
The attached patch modifies the split and rsplit implementations to
avoid
making a copy of self when the split fails to find anything to split on:
>>> s = "abc def"
>>> x = s.split(';')
>>> x[0] is s
True
>>> y = s.rsplit('-')
>>> y[0] is s
True
>>> t = "abcdef"
>>> x = t.split()
>>> x[0] is t
True
>>> y = t.rsplit()
>>> y[0] is t
True
All tests pass. Given that this is just a small optimization I
don't believe any changes to the docs or the existing tests are
necessary.
----------
components: Interpreter Core
files: string-split.patch
keywords: patch
messages: 58081
nosy: skip.montanaro
priority: normal
severity: normal
status: open
title: Avoid string copy when split char doesn't match
type: rfe
versions: Python 2.6
Added file: http://bugs.python.org/file8851/string-split.patch
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1538>
__________________________________
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: string-split.patch
Url: http://mail.python.org/pipermail/new-bugs-announce/attachments/20071202/169ceebb/attachment.txt
More information about the New-bugs-announce
mailing list