On Sat, Aug 03, 2002 at 03:54:07PM -0400, Paul Tremblay wrote:
> On Sat, Aug 03, 2002 at 10:58:24AM +0200, Paul Johnson wrote:
> > 
> > On Fri, Aug 02, 2002 at 02:08:25AM -0400, Paul Tremblay wrote:
> > 
> > > (I know I did a little test with sed, a python script, and a perl
> > > script, just changing the word "the" to "teh" in a huge file. Sed and
> > > python took about he same time, while perl was six times faster.)
> > 
> > This is from the perl source code (sv.c if you are interested):
> > 
> >     /* Here is some breathtakingly efficient cheating */
> > 
> >         if (rslen) {
> >             while (cnt > 0) {                    /* this     |  eat */
> >                 cnt--;
> >                 if ((*bp++ = *ptr++) == rslast)  /* really   |  dust */
> >                     goto thats_all_folks;        /* screams  |  sed :-) */
> >             }
> >         }
> >         else {
> >             Copy(ptr, bp, cnt, char);            /* this     |  eat */
> >             bp += cnt;                           /* screams  |  dust */
> >             ptr += cnt;                          /* louder   |  sed :-) */
> >             cnt = 0;
> >         }
> > 
> > 
> 
> Is this for real, and not a joke? If so, it is pretty funny!

This is for real.  A lot of the perl source code is pretty funny, though
generally not for the same reasons as a lot of other source code is
pretty funny :-)  Larry's posts were usually great fun to read too.

That was a cut and paste from the latest perl release.  But this
particular bit of code and the comments remain pretty much unchanged
from perl 1, nearly 15 years ago.

#ifdef STDSTDIO         /* Here is some breathtakingly efficient cheating */

....

    for (;;) {
      screamer:
        while (--cnt >= 0) {                    /* this */      /* eat */
            if ((*bp++ = *ptr++) == newline)    /* really */    /* dust */
                goto thats_all_folks;           /* screams */   /* sed :-) */ 
        }

....

#else /* !STDSTDIO */   /* The big, slow, and stupid way */

    static char buf[4192];

    if (fgets(buf, sizeof buf, fp) != Nullch)
        str_set(str, buf);
    else
        str_set(str, No);

#endif /* STDSTDIO */

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to