Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:18678 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69599 invoked by uid 1010); 5 Sep 2005 14:08:45 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 69584 invoked from network); 5 Sep 2005 14:08:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Sep 2005 14:08:45 -0000 X-Host-Fingerprint: 195.225.34.5 unknown Received: from ([195.225.34.5:28152] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 67/D1-33268-C615C134 for ; Mon, 05 Sep 2005 10:08:44 -0400 Message-ID: <67.D1.33268.C615C134@pb1.pair.com> To: internals@lists.php.net References: <431C2738.2040602@wp.pl> Date: Mon, 5 Sep 2005 16:02:21 +0200 Lines: 117 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Posted-By: 195.225.34.5 Subject: Re: crc32 From: r.korving@xit.nl ("Ron Korving") Wouldn't it be more practical to implement these as stream filters? Ron "Wojtek Meler" schreef in bericht news:431C2738.2040602@wp.pl... > I've patched original crc32 PHP function to allow incremental crc32 > counting. > It touches only a few lines of original code. > New crc32 function signature is > > int crc32(string str [,int prev_sum]) > > With this patch you can generate crc32 checksum for even large files > without reading it contents to single variable. > Fe. instead of doing > > | $file_string = file_get_contents($file); > $crc = crc32($file_string); > | > you can do > > $crc=0; > $f =fopen($file,'r'); > while ( $data=fread($f,1024)) $crc = crc32($data,$crc); > fclose($f); > > Icremental processing has less memory requirements. > I'd like also change base64_* functions to allow incremental processing. > > Any chances apply such changes ? > > Regards, > Wojtek > ---------------------------------------------------------------------------- ---- > Index: crc32.c > =================================================================== > RCS file: /repository/php-src/ext/standard/crc32.c,v > retrieving revision 1.16 > diff -u -r1.16 crc32.c > --- crc32.c 3 Aug 2005 14:07:57 -0000 1.16 > +++ crc32.c 5 Sep 2005 11:02:00 -0000 > @@ -1,13 +1,13 @@ > /* > +----------------------------------------------------------------------+ > - | PHP Version 5 | > + | PHP Version 4 | > +----------------------------------------------------------------------+ > - | Copyright (c) 1997-2005 The PHP Group | > + | Copyright (c) 1997-2003 The PHP Group | > +----------------------------------------------------------------------+ > - | This source file is subject to version 3.0 of the PHP license, | > + | This source file is subject to version 2.02 of the PHP license, | > | that is bundled with this package in the file LICENSE, and is | > - | available through the world-wide-web at the following url: | > - | http://www.php.net/license/3_0.txt. | > + | available at through the world-wide-web at | > + | http://www.php.net/license/2_02.txt. | > | If you did not receive a copy of the PHP license and are unable to | > | obtain it through the world-wide-web, please send a note to | > | license@php.net so we can mail you a copy immediately. | > @@ -22,20 +22,19 @@ > #include "basic_functions.h" > #include "crc32.h" > > -/* {{{ proto string crc32(string str) > +/* {{{ proto int crc32(string str[,int prev_crc]) > Calculate the crc32 polynomial of a string */ > PHP_NAMED_FUNCTION(php_if_crc32) > { > - unsigned int crc = ~0; > + unsigned int crc = 0; > char *p; > - int len, nr; > + int len; > > - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &p, &nr) == FAILURE) { > + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &p, &len, &crc) == FAILURE) { > return; > } > - > - len = 0 ; > - for (len += nr; nr--; ++p) { > + crc = ~crc; > + for (; len--; ++p) { > CRC32(crc, *p); > } > RETVAL_LONG(~crc); >