Module Name:    src
Committed By:   rillig
Date:           Fri Nov 19 19:55:15 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c indent.h io.c lexi.c

Log Message:
indent: replace ps.procname with ps.is_function_definition

Omly the first character of ps.procname was ever read, and it was only
compared to '\0'.  Using a bool for this means simpler code, less
memory and fewer wasted CPU cycles due to the removed strncpy.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/indent/io.c
cvs rdiff -u -r1.146 -r1.147 src/usr.bin/indent/lexi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.225 src/usr.bin/indent/indent.c:1.226
--- src/usr.bin/indent/indent.c:1.225	Fri Nov 19 18:14:18 2021
+++ src/usr.bin/indent/indent.c	Fri Nov 19 19:55:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.225 2021/11/19 18:14:18 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.226 2021/11/19 19:55:15 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.225 2021/11/19 18:14:18 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.226 2021/11/19 19:55:15 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -671,7 +671,7 @@ process_lparen_or_lbracket(int decl_ind,
 
     if (token.s[0] == '(' && ps.in_decl
 	&& !ps.block_init && !ps.decl_indent_done &&
-	ps.procname[0] == '\0' && ps.paren_level == 0) {
+	!ps.is_function_definition && ps.paren_level == 0) {
 	/* function pointer declarations */
 	code_add_decl_indent(decl_ind, tabs_to_var);
 	ps.decl_indent_done = true;
@@ -756,7 +756,7 @@ static void
 process_unary_op(int decl_ind, bool tabs_to_var)
 {
     if (!ps.decl_indent_done && ps.in_decl && !ps.block_init &&
-	ps.procname[0] == '\0' && ps.paren_level == 0) {
+	!ps.is_function_definition && ps.paren_level == 0) {
 	/* pointer declarations */
 	code_add_decl_indent(decl_ind - (int)buf_len(&token), tabs_to_var);
 	ps.decl_indent_done = true;
@@ -1119,7 +1119,7 @@ process_comma(int decl_ind, bool tabs_to
     ps.want_blank = code.s != code.e;	/* only put blank after comma if comma
 					 * does not start the line */
 
-    if (ps.in_decl && ps.procname[0] == '\0' && !ps.block_init &&
+    if (ps.in_decl && !ps.is_function_definition && !ps.block_init &&
 	!ps.decl_indent_done && ps.paren_level == 0) {
 	/* indent leading commas and not the actual identifiers */
 	code_add_decl_indent(decl_ind - 1, tabs_to_var);

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.96 src/usr.bin/indent/indent.h:1.97
--- src/usr.bin/indent/indent.h:1.96	Fri Nov 19 18:25:50 2021
+++ src/usr.bin/indent/indent.h	Fri Nov 19 19:55:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.96 2021/11/19 18:25:50 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.97 2021/11/19 19:55:15 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -256,10 +256,7 @@ extern struct parser_state {
     bool next_unary;		/* whether the following operator should be
 				 * unary */
 
-    char procname[100];		/* The name of the current procedure; TODO:
-				 * document the difference between procname[0]
-				 * being '\0', ' ' and a real character */
-
+    bool is_function_definition;
 
     bool want_blank;		/* whether the following token should be
 				 * prefixed by a blank. (Said prefixing is

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.124 src/usr.bin/indent/io.c:1.125
--- src/usr.bin/indent/io.c:1.124	Fri Nov 19 18:25:50 2021
+++ src/usr.bin/indent/io.c	Fri Nov 19 19:55:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.124 2021/11/19 18:25:50 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.125 2021/11/19 19:55:15 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.124 2021/11/19 18:25:50 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.125 2021/11/19 19:55:15 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -449,7 +449,7 @@ output_line(char line_terminator)
 {
     static bool first_line = true;
 
-    ps.procname[0] = '\0';
+    ps.is_function_definition = false;
 
     if (code.s == code.e && lab.s == lab.e && com.s == com.e) {
 	if (suppress_blanklines)

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.146 src/usr.bin/indent/lexi.c:1.147
--- src/usr.bin/indent/lexi.c:1.146	Fri Nov 19 19:37:13 2021
+++ src/usr.bin/indent/lexi.c	Fri Nov 19 19:55:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.146 2021/11/19 19:37:13 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.147 2021/11/19 19:55:15 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.146 2021/11/19 19:37:13 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.147 2021/11/19 19:55:15 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -275,8 +275,7 @@ debug_lexi(lexer_symbol lsym)
     debug_ps_bool(next_col_1);
     debug_ps_bool(curr_col_1);
     debug_ps_bool(next_unary);
-    if (strcmp(ps.procname, prev_ps.procname) != 0)
-	debug_println("    ps.procname = \"%s\"", ps.procname);
+    debug_ps_bool(is_function_definition);
     debug_ps_bool(want_blank);
     debug_ps_int(paren_level);
     debug_ps_int(p_l_follow);
@@ -517,7 +516,7 @@ found_typename:
 	    if (*p++ == ')' && (*p == ';' || *p == ','))
 		goto no_function_definition;
 
-	strncpy(ps.procname, token.s, sizeof ps.procname - 1);
+	ps.is_function_definition = true;
 	if (ps.in_decl)
 	    ps.in_parameter_declaration = true;
 	return lsym_funcname;
@@ -705,7 +704,7 @@ lexi(void)
 	    }
 
 	    if (tp < e && *tp == '(')
-		ps.procname[0] = ' ';	/* XXX: why not '\0'? */
+		ps.is_function_definition = true;
 	}
 
 	lsym = lsym_unary_op;

Reply via email to