Mercurial > cpython-lru_cache-weakref
diff Doc/lib/libstdtypes.tex @ 32974:fb6ffd290cfb legacy-trunk
SF patch #980695: efficient string concatenation
(Original patch by Armin Rigo).
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 06 Aug 2004 18:43:09 +0000 |
| parents | 024ff0ab4588 |
| children | 9b188158181f |
line wrap: on
line diff
--- a/Doc/lib/libstdtypes.tex Fri Aug 06 04:30:46 2004 +0000 +++ b/Doc/lib/libstdtypes.tex Fri Aug 06 18:43:09 2004 +0000 @@ -455,7 +455,7 @@ \lineiii{\var{x} not in \var{s}}{\code{0} if an item of \var{s} is equal to \var{x}, else \code{1}}{(1)} \hline - \lineiii{\var{s} + \var{t}}{the concatenation of \var{s} and \var{t}}{} + \lineiii{\var{s} + \var{t}}{the concatenation of \var{s} and \var{t}}{(6)} \lineiii{\var{s} * \var{n}\textrm{,} \var{n} * \var{s}}{\var{n} shallow copies of \var{s} concatenated}{(2)} \hline \lineiii{\var{s}[\var{i}]}{\var{i}'th item of \var{s}, origin 0}{(3)} @@ -536,6 +536,16 @@ (which end depends on the sign of \var{k}). Note, \var{k} cannot be zero. +\item[(6)] If \var{s} and \var{t} are both strings, some Python +implementations such as CPython can usally perform an inplace optimization +for assignments of the form \code{\var{s}=\var{s}+\var{t}} or +\code{\var{s}+=\var{t}}. When applicable, this optimization makes +quadratic run-time much less likely. This optimization is both version +and implementation dependent. For performance sensitive code, it is +preferrable to use the \method{str.join()} method which assures consistent +linear concatenation performance across versions and implementations. +\versionchanged[Formerly, string concatenation never occurred inplace]{2.4} + \end{description}
