From 0aeee8c1c8e8c3fbb2ee2db1000ee7e1aa925cf8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Dec 1997 12:37:40 +0000 Subject: [PATCH] damn, I had implicitly assumed signed characters when writing the rolling checksum code. The result is that rsync worked much more slowly when going between two machines where one of the machines uses signed and the other unsigned chars. The rolling checksum rarely matched so effectively a copy was done in many cases. The data always came through correctly so no file corruption occurred but it's pretty pointless using rsync if it doesn't speed things up! I've now made the sign of the chars explicit --- checksum.c | 3 ++- match.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/checksum.c b/checksum.c index 20158363..7b8035cc 100644 --- a/checksum.c +++ b/checksum.c @@ -30,10 +30,11 @@ extern int remote_version; a simple 32 bit checksum that can be upadted from either end (inspired by Mark Adler's Adler-32 checksum) */ -uint32 get_checksum1(char *buf,int len) +uint32 get_checksum1(char *buf1,int len) { int i; uint32 s1, s2; + signed char *buf = (signed char *)buf1; s1 = s2 = 0; for (i = 0; i < (len-4); i+=4) { diff --git a/match.c b/match.c index 591558fd..a353c83b 100644 --- a/match.c +++ b/match.c @@ -130,16 +130,16 @@ static void hash_search(int f,struct sum_struct *s, int end; char sum2[SUM_LENGTH]; uint32 s1, s2, sum; - char *map; + signed char *map; if (verbose > 2) fprintf(FERROR,"hash search b=%d len=%d\n",s->n,(int)len); k = MIN(len, s->n); - map = map_ptr(buf,0,k); + map = (signed char *)map_ptr(buf,0,k); - sum = get_checksum1(map, k); + sum = get_checksum1((char *)map, k); s1 = sum & 0xFFFF; s2 = sum >> 16; if (verbose > 3) @@ -175,16 +175,16 @@ static void hash_search(int f,struct sum_struct *s, if (!done_csum2) { int l = MIN(s->n,len-offset); - map = map_ptr(buf,offset,l); - get_checksum2(map,l,sum2); + map = (signed char *)map_ptr(buf,offset,l); + get_checksum2((char *)map,l,sum2); done_csum2 = 1; } if (memcmp(sum2,s->sums[i].sum2,csum_length) == 0) { matched(f,s,buf,len,offset,i); offset += s->sums[i].len - 1; k = MIN((len-offset), s->n); - map = map_ptr(buf,offset,k); - sum = get_checksum1(map, k); + map = (signed char *)map_ptr(buf,offset,k); + sum = get_checksum1((char *)map, k); s1 = sum & 0xFFFF; s2 = sum >> 16; ++matches; @@ -198,7 +198,7 @@ static void hash_search(int f,struct sum_struct *s, } /* Trim off the first byte from the checksum */ - map = map_ptr(buf,offset,k+1); + map = (signed char *)map_ptr(buf,offset,k+1); s1 -= map[0] + CHAR_OFFSET; s2 -= k * (map[0]+CHAR_OFFSET); -- 2.34.1