Philippe M. Chiasson wrote:


Stas Bekman wrote:

[EMAIL PROTECTED] wrote:

gozer 2004/09/09 15:16:38



 +/* XXX: There is no XS accessible splice() */
 +static void modperl_av_remove_entry(pTHX_ AV *av, I32 index)
 +{
 +    I32 i;
 +    AV *tmpav = newAV();
 +
 +    /* stash the entries _before_ the item to delete */
 +    for (i=0; i<=index; i++) {
 +        av_store(tmpav, i, SvREFCNT_inc(av_shift(av)));
 +    }
 +     +    /* make size at the beginning of the array */
 +    av_unshift(av, index-1);
 +     +    /* add stashed entries back */
 +    for (i=0; i<index; i++) {
 +        av_store(av, i, *av_fetch(tmpav, i, 0));
 +    }
 +     +    SvREFCNT_dec(tmpav);



shouldn't it just be sv_free'd? how do you know when the enclosing scope will force the free'ing when you can safely free it right here.


I was under the impression that
SV *av = newAV();
[...]
SvREFCNT_dec(av);

would achieve just that.

Yes, but with what price:

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
# define SvREFCNT_dec(sv) \
({ \
SV *_sv = (SV*)(sv); \
if (_sv) { \
if (SvREFCNT(_sv)) { \
if (--(SvREFCNT(_sv)) == 0) \
Perl_sv_free2(aTHX_ _sv); \
} else { \
sv_free(_sv); \
} \
} \
})
#else
Are you saying you'd want to see:
SV *av = newAV();
[...]
av_undef(av);

SV *av = newAV(); ... sv_free(av).

won't that work just as well. I guess you get not much speed improvement here, but it's clear that this is a temp and you free it right there.

--
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to