Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: replace ps.procname with ps.is_functi...
details: https://anonhg.NetBSD.org/src/rev/a22daa7d2cef
branches: trunk
changeset: 1026341:a22daa7d2cef
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Nov 19 19:55:15 2021 +0000
description:
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.
diffstat:
usr.bin/indent/indent.c | 10 +++++-----
usr.bin/indent/indent.h | 7 ++-----
usr.bin/indent/io.c | 6 +++---
usr.bin/indent/lexi.c | 11 +++++------
4 files changed, 15 insertions(+), 19 deletions(-)
diffs (139 lines):
diff -r 9ee2bf7fb5b0 -r a22daa7d2cef usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Nov 19 19:37:13 2021 +0000
+++ b/usr.bin/indent/indent.c Fri Nov 19 19:55:15 2021 +0000
@@ -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 @@
#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 @@
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 @@
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 @@
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);
diff -r 9ee2bf7fb5b0 -r a22daa7d2cef usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Fri Nov 19 19:37:13 2021 +0000
+++ b/usr.bin/indent/indent.h Fri Nov 19 19:55:15 2021 +0000
@@ -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 @@
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
diff -r 9ee2bf7fb5b0 -r a22daa7d2cef usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Fri Nov 19 19:37:13 2021 +0000
+++ b/usr.bin/indent/io.c Fri Nov 19 19:55:15 2021 +0000
@@ -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 @@
#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 @@
{
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)
diff -r 9ee2bf7fb5b0 -r a22daa7d2cef usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Fri Nov 19 19:37:13 2021 +0000
+++ b/usr.bin/indent/lexi.c Fri Nov 19 19:55:15 2021 +0000
@@ -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 @@
#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_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 @@
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 @@
}
if (tp < e && *tp == '(')
- ps.procname[0] = ' '; /* XXX: why not '\0'? */
+ ps.is_function_definition = true;
}
lsym = lsym_unary_op;
Home |
Main Index |
Thread Index |
Old Index