develooper Front page | perl.perl5.porters | Postings from August 2010

Re: Patch to make string-append on win32 100 times faster

Thread Previous | Thread Next
From:
demerphq
Date:
August 2, 2010 03:36
Subject:
Re: Patch to make string-append on win32 100 times faster
Message ID:
AANLkTinqFDWkyCcwk2=M2bSY8D=E0Bu_eNOxCui+=LHO@mail.gmail.com
On 31 July 2010 13:44, David Golden <xdaveg@gmail.com> wrote:
> On Sat, Jul 31, 2010 at 1:14 AM, Eric Brine <ikegami@adaelis.com> wrote:
>> Theres some perl way to do this without explicitly assigning a large string
>>>
>>
>> It involves open(\$var)
>
> Sounds like a new candidate for Scalar::Util.

Here are three ways to do it in perl. The first is interesting as it
works slightly differently in that it enables the OOK flag as well,
which IMO is a bug in substr().

Yves

$ perl -MDevel::Peek -e'$size=10; $str=" " x $size;
substr($str,0,$size,""); Dump($str); $str.="ab"; Dump($str);'
SV = PVIV(0x8ac9fd4) at 0x8ad40c8
  REFCNT = 1
  FLAGS = (POK,OOK,pPOK)
  IV = 10  (OFFSET)
  PV = 0x8acafa2 ( "          " . ) ""\0
  CUR = 0
  LEN = 2
SV = PVIV(0x8ac9fd4) at 0x8ad40c8
  REFCNT = 1
  FLAGS = (POK,pPOK)
  IV = 0
  PV = 0x8acaf98 "ab"\0
  CUR = 2
  LEN = 12
$ perl -MDevel::Peek -e'$size=10; $str=" " x $size; $str=~s/.+//g;
Dump($str); $str.="ab"; Dump($str);'
SV = PV(0x92b1748) at 0x92d10c0
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x92c7f98 ""\0
  CUR = 0
  LEN = 12
SV = PV(0x92b1748) at 0x92d10c0
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x92c7f98 "ab"\0
  CUR = 2
  LEN = 12
$ perl -MDevel::Peek -e'$size=10; $str=" " x $size; chop($str) while
length($str); Dump($str); $str.="ab"; Dump($str);'
SV = PV(0x928c748) at 0x92ac0d0
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x92a2f98 ""\0
  CUR = 0
  LEN = 12
SV = PV(0x928c748) at 0x92ac0d0
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x92a2f98 "ab"\0
  CUR = 2
  LEN = 12




-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About