Matt McCutchen's Web Site
/
rsync
/
rsync.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Rolling over the NEWS from 2.6.7.
[rsync/rsync.git]
/
match.c
diff --git
a/match.c
b/match.c
index
e42abca
..
1f36a58
100644
(file)
--- a/
match.c
+++ b/
match.c
@@
-20,70
+20,47
@@
#include "rsync.h"
extern int verbose;
#include "rsync.h"
extern int verbose;
-extern int am_server;
extern int do_progress;
extern int checksum_seed;
extern int append_mode;
int updating_basis_file;
extern int do_progress;
extern int checksum_seed;
extern int append_mode;
int updating_basis_file;
-typedef unsigned short tag;
-
-#define TABLESIZE (1<<16)
-#define NULL_TAG (-1)
-
static int false_alarms;
static int false_alarms;
-static int
tag
_hits;
+static int
hash
_hits;
static int matches;
static int64 data_transfer;
static int total_false_alarms;
static int matches;
static int64 data_transfer;
static int total_false_alarms;
-static int total_
tag
_hits;
+static int total_
hash
_hits;
static int total_matches;
extern struct stats stats;
static int total_matches;
extern struct stats stats;
-struct target {
- tag t;
- int32 i;
-};
-
-static struct target *targets;
-
-static int32 *tag_table;
-
-#define gettag2(s1,s2) (((s1) + (s2)) & 0xFFFF)
-#define gettag(sum) gettag2((sum)&0xFFFF,(sum)>>16)
+#define TABLESIZE (1<<16)
-static int compare_targets(struct target *t1,struct target *t2)
-{
- return (int)t1->t - (int)t2->t;
-}
+static int32 *hash_table;
+#define SUM2HASH2(s1,s2) (((s1) + (s2)) & 0xFFFF)
+#define SUM2HASH(sum) SUM2HASH2((sum)&0xFFFF,(sum)>>16)
static void build_hash_table(struct sum_struct *s)
{
int32 i;
static void build_hash_table(struct sum_struct *s)
{
int32 i;
- if (!tag_table)
- tag_table = new_array(int32, TABLESIZE);
+ if (!hash_table) {
+ hash_table = new_array(int32, TABLESIZE);
+ if (!hash_table)
+ out_of_memory("build_hash_table");
+ }
- targets = new_array(struct target, s->count);
- if (!tag_table || !targets)
- out_of_memory("build_hash_table");
+ memset(hash_table, 0xFF, TABLESIZE * sizeof hash_table[0]);
for (i = 0; i < s->count; i++) {
for (i = 0; i < s->count; i++) {
- targets[i].i = i;
- targets[i].t = gettag(s->sums[i].sum1);
+ uint32 t = SUM2HASH(s->sums[i].sum1);
+ s->sums[i].chain = hash_table[t];
+ hash_table[t] = i;
}
}
-
- qsort(targets,s->count,sizeof(targets[0]),(int (*)())compare_targets);
-
- for (i = 0; i < TABLESIZE; i++)
- tag_table[i] = NULL_TAG;
-
- for (i = s->count; i-- > 0; )
- tag_table[targets[i].t] = i;
}
}
@@
-128,7
+105,6
@@
static void matched(int f, struct sum_struct *s, struct map_struct *buf,
sum_update(map_ptr(buf, last_match + j, n1), n1);
}
sum_update(map_ptr(buf, last_match + j, n1), n1);
}
-
if (i >= 0)
last_match = offset + s->sums[i].len;
else
if (i >= 0)
last_match = offset + s->sums[i].len;
else
@@
-178,20
+154,22
@@
static void hash_search(int f,struct sum_struct *s,
}
do {
}
do {
- tag t = gettag2(s1,s2);
int done_csum2 = 0;
int done_csum2 = 0;
- int32
j = tag_table[t]
;
+ int32
i
;
- if (verbose > 4)
- rprintf(FINFO,"offset=%.0f sum=%08x\n",(double)offset,sum);
+ if (verbose > 4) {
+ rprintf(FINFO, "offset=%.0f sum=%04x%04x\n",
+ (double)offset, s2 & 0xFFFF, s1 & 0xFFFF);
+ }
- if (j == NULL_TAG)
- goto null_tag;
+ i = hash_table[SUM2HASH2(s1,s2)];
+ if (i < 0)
+ goto null_hash;
sum = (s1 & 0xffff) | (s2 << 16);
sum = (s1 & 0xffff) | (s2 << 16);
-
tag
_hits++;
+
hash
_hits++;
do {
do {
- int32 l
, i = targets[j].i
;
+ int32 l;
if (sum != s->sums[i].sum1)
continue;
if (sum != s->sums[i].sum1)
continue;
@@
-207,9
+185,11
@@
static void hash_search(int f,struct sum_struct *s,
&& !(s->sums[i].flags & SUMFLG_SAME_OFFSET))
continue;
&& !(s->sums[i].flags & SUMFLG_SAME_OFFSET))
continue;
- if (verbose > 3)
- rprintf(FINFO,"potential match at %.0f target=%.0f %.0f sum=%08x\n",
- (double)offset,(double)j,(double)i,sum);
+ if (verbose > 3) {
+ rprintf(FINFO,
+ "potential match at %.0f i=%ld sum=%08x\n",
+ (double)offset, (long)i, sum);
+ }
if (!done_csum2) {
map = (schar *)map_ptr(buf,offset,l);
if (!done_csum2) {
map = (schar *)map_ptr(buf,offset,l);
@@
-226,8
+206,8
@@
static void hash_search(int f,struct sum_struct *s,
* one with an identical offset, so we prefer that over
* the following want_i optimization. */
if (updating_basis_file) {
* one with an identical offset, so we prefer that over
* the following want_i optimization. */
if (updating_basis_file) {
- do {
- int32 i2 = targets[j].i;
+ int32 i2;
+ for (i2 = i; i2 >= 0; i2 = s->sums[i2].chain) {
if (s->sums[i2].offset != offset)
continue;
if (i2 != i) {
if (s->sums[i2].offset != offset)
continue;
if (i2 != i) {
@@
-242,7
+222,7
@@
static void hash_search(int f,struct sum_struct *s,
* both the sender and the receiver. */
s->sums[i].flags |= SUMFLG_SAME_OFFSET;
goto set_want_i;
* both the sender and the receiver. */
s->sums[i].flags |= SUMFLG_SAME_OFFSET;
goto set_want_i;
- }
while (++j < s->count && targets[j].t == t);
+ }
}
/* we've found a match, but now check to see
}
/* we've found a match, but now check to see
@@
-268,9
+248,9
@@
static void hash_search(int f,struct sum_struct *s,
s2 = sum >> 16;
matches++;
break;
s2 = sum >> 16;
matches++;
break;
- } while (
++j < s->count && targets[j].t == t
);
+ } while (
(i = s->sums[i].chain) >= 0
);
-
null_tag
:
+
null_hash
:
backup = offset - last_match;
/* We sometimes read 1 byte prior to last_match... */
if (backup < 0)
backup = offset - last_match;
/* We sometimes read 1 byte prior to last_match... */
if (backup < 0)
@@
-325,7
+305,7
@@
void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
last_match = 0;
false_alarms = 0;
last_match = 0;
false_alarms = 0;
-
tag
_hits = 0;
+
hash
_hits = 0;
matches = 0;
data_transfer = 0;
matches = 0;
data_transfer = 0;
@@
-334,12
+314,16
@@
void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
if (append_mode) {
OFF_T j = 0;
for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) {
if (append_mode) {
OFF_T j = 0;
for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) {
+ if (buf && do_progress)
+ show_progress(last_match, buf->file_size);
sum_update(map_ptr(buf, last_match, CHUNK_SIZE),
CHUNK_SIZE);
last_match = j;
}
if (last_match < s->flength) {
int32 len = s->flength - last_match;
sum_update(map_ptr(buf, last_match, CHUNK_SIZE),
CHUNK_SIZE);
last_match = j;
}
if (last_match < s->flength) {
int32 len = s->flength - last_match;
+ if (buf && do_progress)
+ show_progress(last_match, buf->file_size);
sum_update(map_ptr(buf, last_match, len), len);
last_match = s->flength;
}
sum_update(map_ptr(buf, last_match, len), len);
last_match = s->flength;
}
@@
-373,16
+357,11
@@
void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
rprintf(FINFO,"sending file_sum\n");
write_buf(f,file_sum,MD4_SUM_LENGTH);
rprintf(FINFO,"sending file_sum\n");
write_buf(f,file_sum,MD4_SUM_LENGTH);
- if (targets) {
- free(targets);
- targets=NULL;
- }
-
if (verbose > 2)
if (verbose > 2)
- rprintf(FINFO, "false_alarms=%d
tag
_hits=%d matches=%d\n",
- false_alarms,
tag
_hits, matches);
+ rprintf(FINFO, "false_alarms=%d
hash
_hits=%d matches=%d\n",
+ false_alarms,
hash
_hits, matches);
- total_
tag_hits += tag
_hits;
+ total_
hash_hits += hash
_hits;
total_false_alarms += false_alarms;
total_matches += matches;
stats.literal_data += data_transfer;
total_false_alarms += false_alarms;
total_matches += matches;
stats.literal_data += data_transfer;
@@
-394,8
+373,7
@@
void match_report(void)
return;
rprintf(FINFO,
return;
rprintf(FINFO,
- "total: matches=%d tag_hits=%d false_alarms=%d data=%.0f\n",
- total_matches,total_tag_hits,
- total_false_alarms,
+ "total: matches=%d hash_hits=%d false_alarms=%d data=%.0f\n",
+ total_matches, total_hash_hits, total_false_alarms,
(double)stats.literal_data);
}
(double)stats.literal_data);
}