develooper Front page | perl.perl5.porters | Postings from October 2000

Re: pp_add -> pp_i_add efficiency hack?

Thread Previous | Thread Next
From:
Jarkko Hietaniemi
Date:
October 5, 2000 05:26
Subject:
Re: pp_add -> pp_i_add efficiency hack?
Message ID:
20001005072638.B3141@chaos.wustl.edu
On Thu, Oct 05, 2000 at 01:13:11PM +0100, Simon Cozens wrote:
> On Thu, Oct 05, 2000 at 07:15:28AM -0500, Jarkko Hietaniemi wrote:
> > Urque?  By the time you can are able to say C<$a+3> the looks_like_number
> > thing has already been done and you have an IV/UV/NV called $a.
> 
> Eh? But $a may be a PV. If it's a PV, you have to re-examine it, at
> runtime, to see whether the PV contains an NV or an IV/UV. (If we want

Ahhh, you were talking about PVs.  I think in that case the looks_like_number
is used once and then numeric version is cached.

> to split IV and NV treatment of arithmetic operators) At which point,
> you might as well just use the NV method anyway.

perl -MDevel::Peek -e '$a="123";$b=$a+3;Dump($a)'
SV = PVNV(0x140007c80) at 0x140022140
  REFCNT = 1
  FLAGS = (NOK,POK,pNOK,pPOK)
  IV = 0
  NV = 123
  PV = 0x140001030 "123"\0
  CUR = 3
  LEN = 4

Yup, seems like it becomes an NV.  Grr.  It must be using
some other routine than is being used in parse time since

perl -MDevel::Peek -e '$a=123;$b=$a+3;Dump($a)'  
SV = PVNV(0x140007c80) at 0x140022140
  REFCNT = 1
  FLAGS = (IOK,NOK,pIOK,pNOK)
  IV = 123
  NV = 123
  PV = 0

I must wonder what's the use of ever bothering to try to parse
numbers as IVs/UVs since as soon as they are used they become NVs.

-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen

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