diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-02-28 09:36:12 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-02-28 09:36:12 +0000 |
commit | 5d310ee59b65f3545cc0f2d0b55f1d5c2d2674f8 (patch) | |
tree | fc46ec4667792ae8e2f5ce5515e492f95b51c3de | |
parent | f2b7e07fcd923dde85cf43a00ec0e049eea7924b (diff) |
Refactor blk_match(). Fold the remaining data and empty file or no blocks
cases together since they are kind of the same.
OK tb@
-rw-r--r-- | usr.bin/rsync/blocks.c | 95 |
1 files changed, 42 insertions, 53 deletions
diff --git a/usr.bin/rsync/blocks.c b/usr.bin/rsync/blocks.c index 11f9e2740f0..f76fb81b621 100644 --- a/usr.bin/rsync/blocks.c +++ b/usr.bin/rsync/blocks.c @@ -1,4 +1,4 @@ -/* $OpenBSD: blocks.c,v 1.22 2024/02/27 11:28:30 claudio Exp $ */ +/* $OpenBSD: blocks.c,v 1.23 2024/02/28 09:36:11 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -243,7 +243,7 @@ void blk_match(struct sess *sess, const struct blkset *blks, const char *path, struct blkstat *st) { - off_t last, end, sz; + off_t last, end = 0, sz; int32_t tok; size_t i; const struct blk *blk; @@ -265,66 +265,55 @@ blk_match(struct sess *sess, const struct blkset *blks, */ end = st->mapsz + 1 - blks->blks[blks->blksz - 1].len; - last = st->offs; - - for (i = 0; st->offs < end; st->offs++, i++) { - blk = blk_find(sess, st, blks, path, i == 0); - if (blk == NULL) - continue; - - sz = st->offs - last; - st->dirty += sz; - st->total += sz; - LOG4("%s: flushing %jd B before %zu B block %zu", - path, (intmax_t)sz, - blk->len, blk->idx); - tok = -(blk->idx + 1); - - hash_file_buf(&st->ctx, st->map + last, sz + blk->len); - - /* - * Write the data we have, then follow it with - * the tag of the block that matches. - */ - - st->curpos = last; - st->curlen = st->curpos + sz; - st->curtok = tok; - assert(st->curtok != 0); - st->curst = sz ? BLKSTAT_DATA : BLKSTAT_TOK; - st->total += blk->len; - st->offs += blk->len; - st->hint = blk->idx + 1; - - return; - } - - /* Emit remaining data and send terminator token. */ + } - sz = st->mapsz - last; - LOG4("%s: flushing remaining %jd B", - path, (intmax_t)sz); + last = st->offs; + for (i = 0; st->offs < end; st->offs++, i++) { + blk = blk_find(sess, st, blks, path, i == 0); + if (blk == NULL) + continue; - st->total += sz; + sz = st->offs - last; st->dirty += sz; + st->total += sz; + LOG4("%s: flushing %jd B before %zu B block %zu", + path, (intmax_t)sz, + blk->len, blk->idx); + tok = -(blk->idx + 1); + + hash_file_buf(&st->ctx, st->map + last, sz + blk->len); + + /* + * Write the data we have, then follow it with + * the tag of the block that matches. + */ + st->curpos = last; st->curlen = st->curpos + sz; - st->curtok = 0; + st->curtok = tok; + assert(st->curtok != 0); st->curst = sz ? BLKSTAT_DATA : BLKSTAT_TOK; + st->total += blk->len; + st->offs += blk->len; + st->hint = blk->idx + 1; - hash_file_buf(&st->ctx, st->map + st->curpos, sz); - } else { - st->curpos = 0; - st->curlen = st->mapsz; - st->curtok = 0; - st->curst = st->mapsz ? BLKSTAT_DATA : BLKSTAT_TOK; - st->dirty = st->total = st->mapsz; + return; + } - hash_file_buf(&st->ctx, st->map, st->mapsz); + /* Emit remaining data and send terminator token. */ - LOG4("%s: flushing whole file %zu B", - path, st->mapsz); - } + sz = st->mapsz - last; + LOG4("%s: flushing %s %jd B", path, + last == 0 ? "whole" : "remaining", (intmax_t)sz); + + hash_file_buf(&st->ctx, st->map + last, sz); + + st->total += sz; + st->dirty += sz; + st->curpos = last; + st->curlen = st->curpos + sz; + st->curtok = 0; + st->curst = sz ? BLKSTAT_DATA : BLKSTAT_TOK; } /* |