TextStreamFix

Boris Gaertner Boris.Gaertner at gmx.net
Sat May 24 21:00:48 UTC 2003


At Friday, May 09, 2003 Tim Olson <tim at io.com> 
fixed a bug in TextStream that causes the loss of text 
attributes when the stream buffer grows.
For those who do not remember, here is an example
of the bug:

 |ts |

  ts := TextStream on: (Text new: 10).
  ts  nextPutAll: 'xxxxx' asText.
  ts nextPutAll: ('yyyyy' asText allBold, 'zzzzzzz' asText).
  (Workspace new) contents: ts contents;
   openLabel: 'test'

The second nextPutAll: requires buffer growth and  therefore
the boldness of ''yyyyy' is lost.
When you change the initial size of the buffer from 10 to 100, 
you will get the correct result. With Tims fix, you will always
get the expected result. Thank you Tim!

Tims fix (and speed problems with Scamper) encouraged me
to look a bit closer into the code of TextStream and WriteStream.

TextStream>>nextPutAll: calls  WriteStream>nextPutAll:  to add
an instance of Text.
WriteStream>>nextPutAll:  sends #replaceFrom:to:with: to
the collection (an instance of Text) and that method copies both the
string and the runs of the instance.  I think that it is much better to
use the method #replaceFrom:to:with:startingAt: . This method does
not create a copy of the string, it does a destructive replacement and
that is how a buffer should be used. I combined this fix with the
buffer grow fix from Tim.

The change gives some gain in speed, try this expression without and
with the attached change:

 |ts time |

  ts := TextStream on: (Text new).
  time := Time millisecondsToRun: [100 timesRepeat:
    [ts nextPutAll: ((String new: 5000) atAllPut: $*) asText].].
  time


Hope to see you at CampSmalltalk  :-)

Greetings, Boris


-------------- next part --------------
A non-text attachment was scrubbed...
Name: TextStreamFix2.1.cs
Type: application/octet-stream
Size: 1670 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20030524/7661bb6e/TextStreamFix2.1.obj


More information about the Squeak-dev mailing list