[Newbies] pretty printing
bert at freudenbergs.de
Sun Sep 28 17:12:57 UTC 2008
Am 28.09.2008 um 09:52 schrieb Randal L. Schwartz:
>>>>>> "Claus" == Claus Kick <claus_kick at web.de> writes:
> Claus> YourClass >> escape: aString
> Claus> "escapes a String"
> Claus> |result|
> Claus> result := ''.
> Claus> aString do:[:char | result := result, char xmlEscaped].
> Claus> ^result
> This is an expensive way to build a string. #collect: would be
> aString collect: [:char | char xmlEscaped].
> Internally, that uses a Stream, which extends itself nicely as new
> 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 ;)
- Bert -
More information about the Beginners