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; }
In reply to Help me improve my XS. by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |