[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 
ChiPy list:


The attached patch modifies the split and rsplit implementations to 
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
    >>> y = s.rsplit('-')
    >>> y[0] is s
    >>> t = "abcdef"
    >>> x = t.split()
    >>> x[0] is t
    >>> y = t.rsplit()
    >>> y[0] is t

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

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>
-------------- 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