I've been thinking about this a bit, especially as I play catchup
with a few weeks of p6i mail. Here's my current thinking.
1) COW is useful and trivial in those cases where the original string
data is immobile. Constants, for example, or mmapped files.
$foo = "bar";
$foo _= "baz";
2) COW is mildly useful in those cases where two or more strings
point to the same moveable string data, and one might end up changing
later.
$foo = <>;
$bar = $foo;
chomp $bar;
3) COW is a big pain when we have pointers into the middle of string
data pointed to by other things.
$foo = $bar x 10;
$baz = substr($bar, 20, 30);
Case #1 requires no extra effort on the part of the GC, and the
string mutating functions. (And since we seem to be mostly immutable
strings, that's not too many places)
Case #2 requires the complicity of the garbage collector, so when it
moves data it can update multiple pointers. I'm not sure this is
worth the overhead in the GC, but I could make a case for it.
Case #3 is, honestly, more trouble than it's likely worth to support
at the string level. I can see doing it with PMCs (where you have a
pointer to someone else's string buffer along with an offset and
length stored off the PMC somewhere)
So anyway, I'm not thinking COW will be worth the hassle in any but
case #1. If anyone would care to write the code to prove me wrong,
that's keen with me, but I don't want any patches in the repository
without good proof.
--
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
[EMAIL PROTECTED] have teddy bears and even
teddy bears get drunk