dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit 5f4ef6bbdd11dbb7469365a3f244789e4ea15013
parent 5e1aa604d5f99e97f55d41dd0324cec8b4badd5b
Author: sin <sin@2f30.org>
Date:   Fri, 22 Feb 2019 14:00:37 +0000

Precalculate discriminator

Diffstat:
Mchunker.c | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/chunker.c b/chunker.c @@ -12,6 +12,7 @@ struct chunker { size_t cap; size_t rpos; size_t wpos; + size_t discr; int fd; }; @@ -22,15 +23,13 @@ calc_discr(size_t avg) } static int -match_pattern(size_t chunk_size, uint32_t fp) +match_pattern(struct chunker *chunker, size_t chunk_size, uint32_t fp) { - size_t discr = calc_discr(BLKSIZE_AVG); - if (chunk_size >= BLKSIZE_MAX) return 1; if (chunk_size < BLKSIZE_MIN) return 0; - return (fp % discr) == discr - 1; + return (fp % chunker->discr) == chunker->discr - 1; } static size_t @@ -60,7 +59,7 @@ get_chunk_size(struct chunker *chunker) if (i > 0) fp = buzh_update(fp, bp[i - 1], bp[chunk_size - 1], WINSIZE); - if (match_pattern(chunk_size, fp) == 1) + if (match_pattern(chunker, chunk_size, fp) == 1) return chunk_size; } return chunk_size; @@ -82,6 +81,7 @@ alloc_chunker(size_t cap, int fd) chunker->rpos = 0; chunker->wpos = 0; chunker->fd = fd; + chunker->discr = calc_discr(BLKSIZE_AVG); return chunker; }