git: 7760b8541418 - main - diff: decrease indent level

Piotr Pawel Stefaniak pstef at FreeBSD.org
Wed Sep 15 23:59:54 UTC 2021


The branch main has been updated by pstef:

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

commit 7760b85414189789c792c92c66bb3ddb877deae1
Author:     Piotr Pawel Stefaniak <pstef at FreeBSD.org>
AuthorDate: 2021-09-05 14:26:23 +0000
Commit:     Piotr Pawel Stefaniak <pstef at FreeBSD.org>
CommitDate: 2021-09-15 23:46:44 +0000

    diff: decrease indent level
    
    An upcoming change will add more code in the loop.
---
 usr.bin/diff/diffreg.c | 43 +++++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index 4a00aff9243b..c9095ec46e88 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1378,35 +1378,34 @@ match_function(const long *f, int pos, FILE *fp)
 	const char *state = NULL;
 
 	lastline = pos;
-	while (pos > last) {
+	for (; pos > last; pos--) {
 		fseek(fp, f[pos - 1], SEEK_SET);
 		nc = f[pos] - f[pos - 1];
 		if (nc >= sizeof(buf))
 			nc = sizeof(buf) - 1;
 		nc = fread(buf, 1, nc, fp);
-		if (nc > 0) {
-			buf[nc] = '\0';
-			buf[strcspn(buf, "\n")] = '\0';
-			if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
-				if (begins_with(buf, "private:")) {
-					if (!state)
-						state = " (private)";
-				} else if (begins_with(buf, "protected:")) {
-					if (!state)
-						state = " (protected)";
-				} else if (begins_with(buf, "public:")) {
-					if (!state)
-						state = " (public)";
-				} else {
-					strlcpy(lastbuf, buf, sizeof(lastbuf));
-					if (state)
-						strlcat(lastbuf, state, sizeof(lastbuf));
-					lastmatchline = pos;
-					return (lastbuf);
-				}
+		if (nc == 0)
+			continue;
+		buf[nc] = '\0';
+		buf[strcspn(buf, "\n")] = '\0';
+		if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
+			if (begins_with(buf, "private:")) {
+				if (!state)
+					state = " (private)";
+			} else if (begins_with(buf, "protected:")) {
+				if (!state)
+					state = " (protected)";
+			} else if (begins_with(buf, "public:")) {
+				if (!state)
+					state = " (public)";
+			} else {
+				strlcpy(lastbuf, buf, sizeof(lastbuf));
+				if (state)
+					strlcat(lastbuf, state, sizeof(lastbuf));
+				lastmatchline = pos;
+				return (lastbuf);
 			}
 		}
-		pos--;
 	}
 	return (lastmatchline > 0 ? lastbuf : NULL);
 }


More information about the dev-commits-src-main mailing list