develooper Front page | perl.perl5.porters | Postings from March 2006

Re: CLONE for Tie::RefHash

Thread Previous | Thread Next
From:
demerphq
Date:
March 29, 2006 03:15
Subject:
Re: CLONE for Tie::RefHash
Message ID:
9b18b3110603290314r36553026i9efc039b4d22bbeb@mail.gmail.com
On 3/29/06, Yuval Kogman <nothingmuch@woobling.org> wrote:
> On Wed, Mar 29, 2006 at 13:05:49 +0200, demerphq wrote:
>
> > Well i know from experience on other matters that using StrVal for
> > indexing reference lookups is massively slower than using refaddr. I
> > just whipped up a benchmark and it shows that refaddr is an order of
> > magnitude faster than than StrVal. And IMO if you are already dealing
> > with a piggish interface (ie a tied hash) then you aught to careful
> > about trimming unnecessary fat elsewhere.
>
> Okay, i'm sold...
>
> I'll write a quick patch later today  when I'm back home unless
> someone beats me to it.

Cool.

There is an additional benefit to using refaddr(): it is not
susceptible to reblessing. If you are keying on the results of StrVal
then dont you have an issue when the object is reblessed?

D:\Dev\Jonas>perl -le"$x=bless {},'foo'; print $x; bless $x,'bar'; print $x;"
foo=HASH(0x225730)
bar=HASH(0x225730)

The way this is normally dealt with is you split off the classname
from the string, which is even *more* work. But with refaddr theres no
need:

D:\Dev\Jonas>perl -le"use Scalar::Util qw(refaddr); $x=bless {},'foo';
print refaddr $x; bless $x,'bar'; print refaddr $x;"
2250592
2250592

Cheers,
yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About