Andrew Lentvorski wrote:
> Chuck Esterbrook wrote:
>> But um, wouldn't comparing strings be awfully slow?
>
> Sure, if you only ever used full strings.  However, most languages
> transform constant strings into a pointer and then only work with the
> pointers unless they absolutely have to switch it back to text.
>
> This is one of the reasons why immutable strings are a *good* thing.
> String comparison is effectively only ever a pointer comparison.
No, for this to be true, you very much need something akin to Symbols:

const string foo = "blah";
const string bar = "blah";
const bool aresame = foo == bar; // how to determine

Let's assume, for the moment, that we're using some language where the
const contraint is completely insurmountable. The only way to know foo
and bar are the same is if either the compiler or the runtime takes the
trouble to compare them. Once you've done that, you can do clever things
like using only one copy of "blah" and having foo and bar both point to
it, but *that's exactly what the Symbol mechanism does*.

--Chris

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to