* Thus wrote Alexander Valyalkin ([EMAIL PROTECTED]):
> Here is improved version of crc32() function.
> Features:
> 1) Automatic initialization of crc32tab[] at first call.
>    So, the file crc32.h with definition of this tab is not
>    nessesary any more now.

I'm not sure what advantage this is really giving you being that
gcc will optimize where the data segment should be, vs putting the
data directly into php's memory.


> 2) Speed is improved on large amount of data.

By using a registered int with a do while() statement vs a
foreach() statement, I'd like to see some benchmarks against this.


> 3) Less source size. Current verison has near 6.5Kb length
>    (including crc32.h). My version has only 2.5Kb length.

Source size is futile.

> 
> Below I provided a test (just copy->compile->test)
> and unified diff of /ext/standard/crc32.c
> ...
> 
> /****************************************************/
> /* my crc32 function */
> PHP_NAMED_FUNCTION(php_if_crc32)
> {
>       static unsigned long int crc32tab[256], not_init = 1;
>       if (not_init) {
>               /* init crc32 table */
>               register unsigned long int tmp, i, j, flag_c;
>               for (i = 0; i < 256; i++) {
>                       tmp = i;
>                       j = 8;
>               do {
>                               if (tmp & 1) {
>                                       tmp >>= 1;
>                                       tmp ^= 0xEDB88320; /* CRC32 
>                                       (CCITT-32) poly g(x) = 1 0000 0100 
>                                       1100  0001 0001 1101 1011 0111 */
>                               } else tmp >>= 1;
>                   j--;
>               } while (j);
>                       crc32tab[i] = tmp;
>               }
>               not_init = 0;
>       }
>       /* crc32 calculations */
>     char *str;
>     int len;
>     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)  
> == FAILURE || len < 0) return;

Have you read CODING_STANDARDS yet?


Curt
-- 
I was working on a flat tax proposal, and I accidentally proved there's
no god.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to