]> granicus.if.org Git - php/commitdiff
Implemented FR #53213 (Adler32 algorithm is very slow). Patch by zavasek at
authorAdam Harvey <aharvey@php.net>
Mon, 8 Nov 2010 09:35:33 +0000 (09:35 +0000)
committerAdam Harvey <aharvey@php.net>
Mon, 8 Nov 2010 09:35:33 +0000 (09:35 +0000)
yandex dot ru.

NEWS
ext/hash/hash_adler32.c

diff --git a/NEWS b/NEWS
index 45aace19c86788dd00a95f804c0be4a90711e19a..a2f5622b71945dc59afb51507e8448e385e5fea9 100644 (file)
--- a/NEWS
+++ b/NEWS
 
 - Implemented FR #53238 (Make third parameter of preg_match_all optional).
   (Adam)
+- Implemented FR #53213 (Adler32 algorithm is very slow).
+  (zavasek at yandex dot ru)
 - Implemented FR #52555 (Ability to get HTTP response code). (Paul Dragoonis)
 - Implemented FR #51295 (SQLite3::busyTimeout not existing). (Mark)
 - Implemented FR #49366 (Make slash escaping optional in json_encode()). (Adam)
index 24c63f58521f33191b6619fb12777c5766f556b6..b19cc53021b00e1fd41505256bbc47c27b66d095 100644 (file)
@@ -34,9 +34,16 @@ PHP_HASH_API void PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned cha
        s[0] = context->state & 0xffff;
        s[1] = (context->state >> 16) & 0xffff;
        for (i = 0; i < len; ++i) {
-               s[0] = (s[0] + input[i]) % 65521;
-               s[1] = (s[1] + s[0]) % 65521;
+               s[0] += input[i];
+               s[1] += s[0];
+               if (s[1]>=0x7fffffff)
+               {
+                       s[0] = s[0] % 65521;
+                       s[1] = s[1] % 65521;
+               }
        }
+       s[0] = s[0] % 65521;
+       s[1] = s[1] % 65521;
        context->state = s[0] + (s[1] << 16);
 }