Skip to content

Commit

Permalink
Use adler32() from zlib instead of defining our own.
Browse files Browse the repository at this point in the history
Since we already depend on zlib, we don't need to define our
own adler32().  Spotted by oprofile.

Signed-off-by: Peter Eriksen <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Peter Eriksen authored and Junio C Hamano committed Feb 5, 2006
1 parent 9523a4c commit 04fe2a1
Showing 1 changed file with 1 addition and 38 deletions.
39 changes: 1 addition & 38 deletions diff-delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <stdlib.h>
#include "delta.h"
#include "zlib.h"


/* block size: min = 16, max = 64k, power of 2 */
Expand All @@ -30,44 +31,6 @@
#define GR_PRIME 0x9e370001
#define HASH(v, b) (((unsigned int)(v) * GR_PRIME) >> (32 - (b)))

/* largest prime smaller than 65536 */
#define BASE 65521

/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define NMAX 5552

#define DO1(buf, i) { s1 += buf[i]; s2 += s1; }
#define DO2(buf, i) DO1(buf, i); DO1(buf, i + 1);
#define DO4(buf, i) DO2(buf, i); DO2(buf, i + 2);
#define DO8(buf, i) DO4(buf, i); DO4(buf, i + 4);
#define DO16(buf) DO8(buf, 0); DO8(buf, 8);

static unsigned int adler32(unsigned int adler, const unsigned char *buf, int len)
{
int k;
unsigned int s1 = adler & 0xffff;
unsigned int s2 = adler >> 16;

while (len > 0) {
k = MIN(len, NMAX);
len -= k;
while (k >= 16) {
DO16(buf);
buf += 16;
k -= 16;
}
if (k != 0)
do {
s1 += *buf++;
s2 += s1;
} while (--k);
s1 %= BASE;
s2 %= BASE;
}

return (s2 << 16) | s1;
}

static unsigned int hashbits(unsigned int size)
{
unsigned int val = 1, bits = 0;
Expand Down

0 comments on commit 04fe2a1

Please sign in to comment.