Am 28.09.2008 um 10:12 schrieb Bert Freudenberg:

Am 28.09.2008 um 09:52 schrieb Randal L. Schwartz:

This is an expensive way to build a string. #collect: would be better:

aString collect: [:char | char xmlEscaped].

Internally, that uses a Stream, which extends itself nicely as new data appears. In your version, the early string data is getting repeatedly copied
to make each new string.  Ouch.


Err, #collect: constructs a string character by character, not from other strings. Double-ouch ;)


Guess I have to provide an alternative:

#('&' '&amp;' '<' '&lt;' '>' '&gt;' '''' '&apos;' '"' '&quot;')
        pairsDo: [:c :s| string := string copyReplaceAll: c with: s].

which is invariant under pretty-printing so must be good ;)

(this is the same approach as in String>>asHTML)

- Bert -


_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to