This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author skip.montanaro
Recipients skip.montanaro
Date 2007-12-02.07:51:01
SpamBayes Score 0.0014263004
Marked as misclassified No
Message-id <1196581862.98.0.506596232577.issue1538@psf.upfronthosting.co.za>
In-reply-to
Content
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.
Files
File name Uploaded
string-split.patch skip.montanaro, 2007-12-02.07:51:01
History
Date User Action Args
2007-12-02 07:51:03skip.montanarosetspambayes_score: 0.0014263 -> 0.0014263004
recipients: + skip.montanaro
2007-12-02 07:51:03skip.montanarosetspambayes_score: 0.0014263 -> 0.0014263
messageid: <1196581862.98.0.506596232577.issue1538@psf.upfronthosting.co.za>
2007-12-02 07:51:02skip.montanarolinkissue1538 messages
2007-12-02 07:51:02skip.montanarocreate