[Python-Dev] Auto-str and auto-unicode in join (original) (raw)
Nick Coghlan ncoghlan at iinet.net.au
Tue Aug 31 23:00:43 CEST 2004
- Previous message: [Python-Dev] Auto-str and auto-unicode in join
- Next message: [Python-Dev] Re: [Python-checkins] python/dist/src/Lib/test test_string.py, 1.25, 1.26
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
M.-A. Lemburg wrote:
Tim Peters wrote:
If we were to do auto-str, it would be better to rewrite str.join() as a 1-pass algorithm, using the kind of "double allocated space as needed" gimmick unicode.join uses. It would be less efficient if auto-promotion to Unicode turns out to be required, but it's hard to measure how little I care about that; it might be faster if auto-str and Unicode promotion aren't needed (as only 1 pass would be needed). FWIW, I'm -1 on doing auto-conversion using str()/unicode() in .join().
I'm leaning that way myself. The 'auto-str' behaviour gives significant speed increases over the ''.join([str(x) for x in seq]) idiom, but the semantics become tricky when unicode, strings and things which are neither get mixed in the sequence. It also increases the complexity of the C code for the join methods.
(Note that the version of auto-str I tried out doesn't actually mimic the list comprehension idiom - it tries to detect unicode and switch join implementations as appropriate, etc, etc.)
Cheers, Nick.
- Previous message: [Python-Dev] Auto-str and auto-unicode in join
- Next message: [Python-Dev] Re: [Python-checkins] python/dist/src/Lib/test test_string.py, 1.25, 1.26
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]