On 3/13/14, 8:24 AM, Steven Schveighoffer wrote:
Proposal: iff you are setting the length of an array via the length property AND you are setting the length to 0 AND the array starts at the beginning of the block AND the array is mutable (not const or immutable), THEN assumeSafeAppend is called on that array AUTOMATICALLY.
I think this is a sensible proposal, and well argued. However it may break code (even code that arguably wasn't really nicely thought through), and in subtle ways. "We upgraded the compiler, and our 50KLOC app now produces invalid results." Very hard to get working on that, in particular since it's unclear whether this particular matter was the actual culprit.
I think there's a much simpler approach that could help. Define and document a function clearForAppend that resets the length to 0 and puts the array in gear for appending. Maybe an optional parameter indicates a minimum desired capacity.
Then people who want to migrate from D1 to D2 or generally consider using this idiom can grep their source code for "length *= *0" and make the change on their own pace and with appropriate testing.
Andrei