diff options
| author | rillig <rillig@NetBSD.org> | 2023-06-14 21:35:01 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-06-14 21:35:01 +0000 |
| commit | 8d10912f2d5d1ba2f65c3ce7e67f9e0b77b84d94 (patch) | |
| tree | d85a154110916b460804444c6f4ac16f30a9cb84 /usr.bin/indent | |
| parent | a97d7220550b7766495ffc8885a0b2c49efa4564 (diff) | |
indent: reduce number of relocations
Since all command line options modify a member of struct options, there
is no need to encode that relocation 38 times.
No functional change.
Diffstat (limited to 'usr.bin/indent')
| -rw-r--r-- | usr.bin/indent/args.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c index c33d99db561..64ade0b2a5b 100644 --- a/usr.bin/indent/args.c +++ b/usr.bin/indent/args.c @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.83 2023/06/10 16:43:55 rillig Exp $ */ +/* $NetBSD: args.c,v 1.84 2023/06/14 21:35:01 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,12 +38,13 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: args.c,v 1.83 2023/06/10 16:43:55 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.84 2023/06/14 21:35:01 rillig Exp $"); /* Read options from profile files and from the command line. */ #include <err.h> #include <limits.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -51,17 +52,18 @@ __RCSID("$NetBSD: args.c,v 1.83 2023/06/10 16:43:55 rillig Exp $"); #include "indent.h" #if __STDC_VERSION__ >= 201112L -#define assert_type(expr, type) _Generic((expr), type : (expr)) +#define get_offset(name, type) \ + _Generic((&opt.name), type *: offsetof(struct options, name)) #else -#define assert_type(expr, type) (expr) +#define get_offset(name, type) (offsetof(struct options, name)) #endif #define bool_option(name, value, var) \ - {name, true, false, value, 0, 0, assert_type(&(opt.var), bool *)} + {name, true, false, value, 0, 0, get_offset(var, bool)} #define bool_options(name, var) \ - {name, true, true, false, 0, 0, assert_type(&(opt.var), bool *)} + {name, true, true, false, 0, 0, get_offset(var, bool)} #define int_option(name, var, min, max) \ - {name, false, false, false, min, max, assert_type(&(opt.var), int *)} + {name, false, false, false, min, max, get_offset(var, int)} /* See set_special_option for special options. */ static const struct pro { @@ -71,7 +73,7 @@ static const struct pro { bool p_bool_value; /* only relevant if !p_may_negate */ short i_min; short i_max; - void *p_var; /* the associated variable */ + unsigned short opt_offset; /* the associated variable */ } pro[] = { bool_options("bacc", blank_line_around_conditional_compilation), bool_options("bad", blank_line_after_decl), @@ -232,7 +234,7 @@ found: errx(1, "%s: unknown option \"-%s\"", option_source, arg); - *(bool *)p->p_var = + *(bool *)((unsigned char *)(void *)&opt + p->opt_offset) = p->p_may_negate ? arg[0] != 'n' : p->p_bool_value; return; } @@ -250,7 +252,7 @@ found: "must be between %d and %d", option_source, arg_arg, p->p_name, p->i_min, p->i_max); - *(int *)p->p_var = (int)num; + *(int *)((unsigned char *)(void *)&opt + p->opt_offset) = (int)num; } static void |
