Front page | perl.perl5.porters |
Postings from October 2002
Re: Collections
Thread Previous
|
Thread Next
From:
Nicholas Clark
Date:
October 2, 2002 14:53
Subject:
Re: Collections
Message ID:
20021002212433.GD283@Bagpuss.unfortu.net
On Wed, Oct 02, 2002 at 11:46:39AM +0100, Tim Bunce wrote:
> On Tue, Oct 01, 2002 at 02:07:01PM -0400, Michael G Schwern wrote:
> > On Tue, Oct 01, 2002 at 03:33:17PM +0100, Tim Bunce wrote:
> > > Given Hugo's (excellent) "make the core smaller and faster" agenda
> > > I think the best way forward (or at least a very good way forward)
> > > is just to rewrite Tie::RefHash as an extension. It's a pretty
> > > simple bit of code and calling XS subs is very fast (it's specially
> > > optimised).
> >
> > Arthur found that years ago, Sarathy put in a set of functions to make
> > hashes use SVs for keys with the intention of using them for tied hashes.
> > http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/9605/msg00790.html
>
> Yes, that's what makes Tie::RefHash work. Without it the STORE
> method would be given the stringified ref and Tie::RefHash could
> not be implemented.
>
> > Perhaps Tie::RefHash could be modified to call these directly rather than
> > using the tie() interface?
>
> Nope. The underlying perl hashes cannot store SV's as keys.
> The _interface_ supports it, in order to support tied hashes,
> but for non-tied hashes the code just stringifies the key.
The flags seem to be in place to support it:
#define HeSVKEY(he) ((HeKEY(he) && \
HeKLEN(he) == HEf_SVKEY) ? \
HeKEY_sv(he) : Nullsv)
#define HeKEY(he) HEK_KEY(HeKEY_hek(he))
#define HeKEY_sv(he) (*(SV**)HeKEY(he))
but there's nothing behind them.
As an aside, why does perl define
#define PERL_MAGIC_uvar_elem 'u' /* Reserved for use by extensions */
but have no entry for it in the switch in Perl_sv_magic?
If you put 'U' magic on a hash (I was trying things) you croak because there
is no entry for 'u' magic
I suspect a fast general case solution which doesn't slow the general case of
non-special hashes would be to have magic on the hash similar to tie magic, but
call C functions direct rather than a perl method STORE/FETCH/etc
I believe that even writing a tied refhash in XS would still necessitate a
trip into and out of "perl" every time an XS method was called. But I don't
know this stuff at all well, so I could well be wrong.
Nicholas Clark
--
Even better than the real thing: http://nms-cgi.sourceforge.net/
Thread Previous
|
Thread Next