[Cuis-dev] Immutability package
ken.dickey at whidbey.com
ken.dickey at whidbey.com
Fri May 8 07:44:58 PDT 2020
On 2020-05-08 06:15, Juan Vuletich via Cuis-dev wrote:
Something else that would be great is to gradually make Strings
immutable. That would allow us to replace String with Rope if desired.
Actually, Ropes are (or are supposed to be) immutable.
Strings to Ropes is more of a style change.
The main difference is that operations on ropes (e.g. #at:put:) return a
_new_ rope, where Strings are mutated in place. So the first change
would be ensuring all String mutators return a reference to the mutated
String instance and all senders use the latest reference.
This can make Undo easier. Just chain/push ref to previous ropes. Undo
is pop last & redraw.
If we made Text operations functional as well, TextEditor should have a
simplified Undo.
Different costs.
Note that I did Ropes as preparation for using them in Unicode, where
UniChars can be 1, 2, or 4 bytes. When inserting a Chinese character in
an ASCII text string in Squeak, the Chinese character is a "wide"
character, so Squeak changes the entire String to *all* wide characters,
doubling its storage size. UniStrings are Ropes, so adding a Chinese
UniChar just keeps a reference to the old Rope and remembers where the
new char is for #at: and #at:put: . This memory is _much_ cheaper than
doubling storage for the large strings typically used in text editing.
Details in EnhancedText repository.
Cheer,
-KenD
More information about the Cuis-dev
mailing list