1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 17:57:59 +00:00

Merge pull request #2832 from rciorba/hash_modulo_speedup

replace modulo with if to check for wraparound in hashmap
This commit is contained in:
TW 2017-07-21 22:32:21 +02:00 committed by GitHub
commit 0c6a11a9f2

View file

@ -146,7 +146,10 @@ hashindex_lookup(HashIndex *index, const void *key, int *start_idx)
} }
return idx; return idx;
} }
idx = (idx + 1) % index->num_buckets; idx++;
if (idx >= index->num_buckets) {
idx -= index->num_buckets;
}
if(idx == start) { if(idx == start) {
break; break;
} }
@ -547,7 +550,10 @@ hashindex_set(HashIndex *index, const void *key, const void *value)
} }
idx = start_idx; idx = start_idx;
while(!BUCKET_IS_EMPTY(index, idx) && !BUCKET_IS_DELETED(index, idx)) { while(!BUCKET_IS_EMPTY(index, idx) && !BUCKET_IS_DELETED(index, idx)) {
idx = (idx + 1) % index->num_buckets; idx++;
if (idx >= index->num_buckets){
idx -= index->num_buckets;
}
} }
if(BUCKET_IS_EMPTY(index, idx)){ if(BUCKET_IS_EMPTY(index, idx)){
index->num_empty--; index->num_empty--;