Why invariants in D 2.0 std.string?

David B. Held dheld at codelogicconsulting.com
Tue Nov 6 20:33:11 PST 2007


Nathan Reed wrote:
> Janice Caron wrote:
>> I kinda like that.
>>
>> I imagine the reasoning is that the library functions will go faster,
>> because they can be optimised better.
> 
> How does invariant allow better optimization than const?
> [...]

A const string may be intrinsically mutable but you only have a 
read-only view of it.  An invariant string is intrinsically immutable, 
so you can make extra assumptions about what it won't do while you poke it.

Dave



More information about the Digitalmars-d mailing list