BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
As a follow up to Efficient walk/iterate along a string, I started playing with an inline C callback iterator. The following works even with the commented out lines and doesn't appear to leak at all.
However, when I tried to run it as part of a benchmark, it crashes.
So, ignoring the absence of error checking, my questions are:
eg, where does multicall.h come from?
#! perl -sw use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'strIter', CLEAN_AFTER_BUILD => 0; void strIter( SV *code, SV *string ) { dSP; STRLEN i ; char *p = SvPVX( string ); SV *c; // ENTER; // SAVETMPS; c = newSV( 1 ); SvCUR( c ) = 1; SvLEN( c ) = 2; SvPVX( c ) = p; SvPOK_only( c ); GvSV(PL_defgv) = c; for( i=0; i < SvCUR( string ); ++i ) { PUSHMARK(SP); call_sv( code, G_NOARGS |G_VOID ); PUTBACK; SvPVX( c ) = ++p; SvPOK_only( c ); } // FREETMPS; // LEAVE; GvSV(PL_defgv) = string; } END_C use strict; use Time::HiRes qw[ time ]; use Benchmark qw[ cmpthese ]; our $string = 'abcdefghijklmnopqrstuvwyxABCDEFGHIJKLMNOPQRSTUVWXY' x 1 +00; for (1 .. 100 ) { strIter sub{ print; }, $string; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help me improve my XS.
by Tux (Canon) on Nov 23, 2010 at 16:18 UTC | |
|
Re: Help me improve my XS.
by ReturnOfThelonious (Beadle) on Nov 23, 2010 at 22:50 UTC | |
by syphilis (Archbishop) on Nov 24, 2010 at 09:52 UTC | |
by ikegami (Patriarch) on Nov 24, 2010 at 17:15 UTC | |
|
Re: Help me improve my XS.
by ikegami (Patriarch) on Nov 24, 2010 at 01:36 UTC | |
|
Re: Help me improve my XS.
by ikegami (Patriarch) on Nov 24, 2010 at 00:34 UTC | |
by ikegami (Patriarch) on Nov 24, 2010 at 01:08 UTC |