Date: Wed, 5 May 2021 08:38:22 GMT From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: b6b26cecc0ba - stable/13 - diff: simplify the hash functions Message-ID: <202105050838.1458cMgs043707@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=b6b26cecc0babc7834c026b43bb761cbd5147ed9 commit b6b26cecc0babc7834c026b43bb761cbd5147ed9 Author: Baptiste Daroussin <bapt@FreeBSD.org> AuthorDate: 2021-01-26 15:25:00 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2021-05-05 08:37:09 +0000 diff: simplify the hash functions Instead of 3 different complex case they have all been folded into a simple on based on switch (cherry picked from commit e43239f5140e1b80de122458a2ac037172866058) --- usr.bin/diff/diffreg.c | 77 ++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 50 deletions(-) diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 9839171c5639..35d41b28fb7c 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1350,64 +1350,41 @@ readhash(FILE *f, int flags) sum = 1; space = 0; - if ((flags & (D_FOLDBLANKS|D_IGNOREBLANKS)) == 0) { - if (flags & D_IGNORECASE) - for (i = 0; (t = getc(f)) != '\n'; i++) { - if (flags & D_STRIPCR && t == '\r') { - t = getc(f); - if (t == '\n') - break; - ungetc(t, f); - } - if (t == EOF) { - if (i == 0) - return (0); + for (i = 0;;) { + switch (t = getc(f)) { + case '\r': + if (flags & D_STRIPCR) { + t = getc(f); + if (t == '\n') break; - } - sum = sum * 127 + chrtran(t); - } - else - for (i = 0; (t = getc(f)) != '\n'; i++) { - if (flags & D_STRIPCR && t == '\r') { - t = getc(f); - if (t == '\n') - break; - ungetc(t, f); - } - if (t == EOF) { - if (i == 0) - return (0); - break; - } - sum = sum * 127 + t; + ungetc(t, f); } - } else { - for (i = 0;;) { - switch (t = getc(f)) { - case '\r': - case '\t': - case '\v': - case '\f': - case ' ': + /* FALLTHROUGH */ + case '\t': + case '\v': + case '\f': + case ' ': + if ((flags & (D_FOLDBLANKS|D_IGNOREBLANKS)) != 0) { space++; continue; - default: - if (space && (flags & D_IGNOREBLANKS) == 0) { - i++; - space = 0; - } - sum = sum * 127 + chrtran(t); + } + /* FALLTHROUGH */ + default: + if (space && (flags & D_IGNOREBLANKS) == 0) { i++; - continue; - case EOF: - if (i == 0) - return (0); - /* FALLTHROUGH */ - case '\n': - break; + space = 0; } + sum = sum * 127 + chrtran(t); + i++; + continue; + case EOF: + if (i == 0) + return (0); + /* FALLTHROUGH */ + case '\n': break; } + break; } /* * There is a remote possibility that we end up with a zero sum.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105050838.1458cMgs043707>