Message58081
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. |
|
| Date |
User |
Action |
Args |
| 2007-12-02 07:51:03 | skip.montanaro | set | spambayes_score: 0.0014263 -> 0.0014263 recipients:
+ skip.montanaro |
| 2007-12-02 07:51:03 | skip.montanaro | set | spambayes_score: 0.0014263 -> 0.0014263 messageid: <1196581862.98.0.506596232577.issue1538@psf.upfronthosting.co.za> |
| 2007-12-02 07:51:02 | skip.montanaro | link | issue1538 messages |
| 2007-12-02 07:51:02 | skip.montanaro | create | |
|