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.
Created on 2007年12月02日 07:51 by skip.montanaro, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| string-split.patch | skip.montanaro, 2007年12月04日 01:03 | |||
| Messages (4) | |||
|---|---|---|---|
| msg58081 - (view) | Author: Skip Montanaro (skip.montanaro) * (Python triager) | Date: 2007年12月02日 07:51 | |
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. |
|||
| msg58145 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2007年12月03日 19:23 | |
I think this is not quite right; you shouldn't return self unless it is an exact string instance. If it is a subclass of PyString should make a copy. |
|||
| msg58169 - (view) | Author: Skip Montanaro (skip.montanaro) * (Python triager) | Date: 2007年12月04日 01:03 | |
I'm not sure why a string subclass shouldn't work, but I've attached a new version of the patch that calls PyString_CheckExact() to prevent using a string subclass. |
|||
| msg58295 - (view) | Author: Skip Montanaro (skip.montanaro) * (Python triager) | Date: 2007年12月08日 15:34 | |
In the absence of any more feedback, I checked this in as r59420. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:28 | admin | set | github: 45879 |
| 2007年12月08日 15:34:09 | skip.montanaro | set | status: open -> closed resolution: accepted messages: + msg58295 |
| 2007年12月04日 01:03:45 | skip.montanaro | set | files: - string-split.patch |
| 2007年12月04日 01:03:38 | skip.montanaro | set | files:
+ string-split.patch messages: + msg58169 |
| 2007年12月03日 19:23:33 | gvanrossum | set | nosy:
+ gvanrossum messages: + msg58145 |
| 2007年12月02日 07:51:02 | skip.montanaro | create | |