Kyle R . Burton on Mon, 18 Jun 2001 09:49:30 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: adjusting the length of an SV?


> > Sorry, I found it in perlguts:
> > 
> >   SvCUR_set(SV*,I32)
> 
> 
> Note that you should not null out characters - Perl has 8-bit clean strings,
> and a null is a valid character.

Is it better then to just shorten the length of scalar with SvCUR_set?
If I just shorten it using SvCUR_set is it then ok to null out bytes
that are beyond the length of the scalar?

What I'm trying to do is shorten a scalar if specific sets or
sequences of characters are present at the end of a scalar.
Performance is of the utmost priority with this code, so I'm exploring
using Inline to change it from a series of s/// statements into a single
C function call with hardcoded cases for determining when and how to
strip the suffixes off the end of the string.  

To make the C code have an easier time working with subsequent suffixes,
I was nulling out (*p = '\0';) bytes to lop off suffixes once found so
they wouldn't interfere with the remaining series of tests.  Once they
were all removed, I am [now] shortening the string using SvCUR_set.

I'm hoping that by working directly with the SV, and avoiding copying it
at all that it will be faster than otherwise.  So far, using a
C function with hard-coded suffix cases is quite a bit faster than the
s/// code in Perl.


Thanks,
Kyle


-- 
------------------------------------------------------------------------------
   Of course power tools and alcohol don't mix.  Everyone knows power tools 
   aren't soluble in alcohol...      -- Crazy Nigel
mortis@voicenet.com                            http://www.voicenet.com/~mortis
------------------------------------------------------------------------------
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**