The branch main has been updated by bapt:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=e43239f5140e1b80de122458a2ac037172866058

commit e43239f5140e1b80de122458a2ac037172866058
Author:     Baptiste Daroussin <[email protected]>
AuthorDate: 2021-01-26 15:25:00 +0000
Commit:     Baptiste Daroussin <[email protected]>
CommitDate: 2021-01-27 11:28:26 +0000

    diff: simplify the hash functions
    
    Instead of 3 different complex case they have all been folded into a
    simple on based on switch
---
 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 f8c25f822147..564032751862 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1349,64 +1349,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.
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "[email protected]"

Reply via email to