develooper Front page | perl.perl5.porters | Postings from July 2001

RE: [ID 20010703.002] [5.6.2-to-be] PerlIO is EVIL

Thread Previous | Thread Next
From:
vkonovalov
Date:
July 6, 2001 07:10
Subject:
RE: [ID 20010703.002] [5.6.2-to-be] PerlIO is EVIL
Message ID:
E3FB32585BF1D411B9E900805FF51A0808C416@RU0022EXCH001U
> >Additionally, there are several places where local temporary 
> variables assigned just to make further assignment less verbose. 
> >("buf" in PerlIOStdio_read function is an example).
> 
> That is not the reason. The reason is to get the 
> function/macro calls out of the 
> inner loop.

Sorry, I can't see any loops there:

SSize_t
PerlIOStdio_read(PerlIO *f, void *vbuf, Size_t count)
{
 dSYS;
 FILE *s = PerlIOSelf(f,PerlIOStdio)->stdio;
 SSize_t got = 0;
 if (count == 1)
  {
   STDCHAR *buf = (STDCHAR *) vbuf;
   /* Perl is expecting PerlIO_getc() to fill the buffer
    * Linux's stdio does not do that for fread()
    */
   int ch = PerlSIO_fgetc(s);
   if (ch != EOF)
    {
     *buf = ch;
     got = 1;
    }
  }
 else
  got = PerlSIO_fread(vbuf,1,count,s);
 return got;
}



Anyway, that tiny snippet of code is not essential, so it does not worth much debating...


> >IMHO while idea of perlio.c is good, and it allows cool 
> things, it's implementation could be cleaned greatly.
> 
> Patches welcome.

Okay. 
Here is a tiny-optimization patch. Although patch is obvious, I checked for perl to pass tests after applying it.

--- d:\WORK\PerlCompile\perl@11148-orig\perlio.c	Sat Jun 30 22:41:57 2001
+++ d:\WORK\PerlCompile\perl@11148\perlio.c	Fri Jul  6 17:07:24 2001
@@ -2278,14 +2278,13 @@
  SSize_t got = 0;
  if (count == 1)
   {
-   STDCHAR *buf = (STDCHAR *) vbuf;
    /* Perl is expecting PerlIO_getc() to fill the buffer
     * Linux's stdio does not do that for fread()
     */
    int ch = PerlSIO_fgetc(s);
    if (ch != EOF)
     {
-     *buf = ch;
+     *((STDCHAR *)vbuf) = ch;
      got = 1;
     }
   }


I'm not sure that I am able to produce more essential patches, but I'll try.

Best wishes,
<!ENTITY Vadim REALLIFE "Vadim V.Konovalov, St.Petersburg, Russia">
&Vadim;

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