Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:18675 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9506 invoked by uid 1010); 5 Sep 2005 11:30:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 9487 invoked from network); 5 Sep 2005 11:30:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Sep 2005 11:30:34 -0000 Received: from ([127.0.0.1:20528]) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with ECSTREAM id 89/5B-33268-A5C2C134 for ; Mon, 05 Sep 2005 07:30:34 -0400 X-Host-Fingerprint: 212.77.102.105 mail.wp-sa.pl Solaris 9 Received: from ([212.77.102.105:55304] helo=mail.wp-sa.pl) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 4A/3B-33268-F372C134 for ; Mon, 05 Sep 2005 07:08:47 -0400 Received: from [10.10.1.130] (it.wp-sa.pl [212.77.105.136]) by mail.wp-sa.pl (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0IMC00ENBCAGAZ@mail.wp-sa.pl> for internals@lists.php.net; Mon, 05 Sep 2005 13:08:40 +0200 (CEST) Date: Mon, 05 Sep 2005 13:08:40 +0200 To: internals@lists.php.net Message-ID: <431C2738.2040602@wp.pl> MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_3N/ScRAh0Jfb9tF+4UkI0g)" X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) Subject: crc32 From: wmeler@wp.pl (Wojtek Meler) --Boundary_(ID_3N/ScRAh0Jfb9tF+4UkI0g) Content-type: text/plain; charset=ISO-8859-2; format=flowed Content-transfer-encoding: 7BIT 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 --Boundary_(ID_3N/ScRAh0Jfb9tF+4UkI0g) Content-type: text/x-patch; name=crc.patch Content-transfer-encoding: 7BIT Content-disposition: inline; filename=crc.patch 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); --Boundary_(ID_3N/ScRAh0Jfb9tF+4UkI0g)--