[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: References (as in Perl)
- From: "Gavin Kistner" <gavin.kistner@...>
- Date: Mon, 18 Dec 2006 11:21:53 -0700
From: Rici Lake
> On 18-Dec-06, at 12:20 PM, Gavin Kistner wrote:
> > local a = "foo"
> > local b = "foo"
> > local c = b
> > Are 3 strings allocated and maintained internally?
> Only one. Strings are indeed hashed and only unique sequences
> are stored in memory.
>
> As you say, it's an implementation detail, but one of the
> consequences is that string equality comparisons are simply a
> pointer comparison, and hence as fast as any other primitive
> equality comparison.
Ooh, that is an interesting consequence. So there's (some) extra
overhead in creating a string (the hashing), but if I happen to already
have the strings sitting around...well, then there's no reason to shove
them as keys in a table-as-hash in an attempt to speed up comparisons.
Thanks for the insight into the murky (to me) internals. :)