Re: [hackers] [slock][PATCH] Improve option parsing routine

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sat, 29 Oct 2016 11:40:24 +0200

On Sat, Oct 29, 2016 at 12:32 AM, Klemens Nanni <kl3_AT_posteo.org> wrote:
> This reduces the amount of strcmp() calls and comparisons in general to
> a minimum.
> ---
> slock.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/slock.c b/slock.c
> index 283b04e..e9b050a 100644
> --- a/slock.c
> +++ b/slock.c
> _AT_@ -298,15 +298,14 @@ main(int argc, char *argv[]) {
> Display *dpy;
> int s, nlocks, nscreens;
>
> - if (argc > 1 && !strncmp("-", argv[1], 1)) {
> - if ((argc == 2 && !strcmp("-v", argv[1])) ||
> - (argc == 3 && !strcmp("-v", argv[1]) && !strcmp("--", argv[2]))) {
> + if (argv[1] && argv[1][0] == '-') {
> + if (argv[1][1] == 'v' && argv[1][2] == '\0' &&
> + (argc == 2 || (argc == 3 && !strcmp(argv[2], "--")))) {
> fputs("slock-"VERSION"\n", stderr);
> return 0;
> - } else if (!strcmp("--", argv[1])) {
> - --argc;
> - ++argv;
> - } else
> + } else if (argv[1][1] == '-' && argv[1][2] == '\0')
> + --argc, ++argv;
> + else
> die("usage: slock [-v] [cmd [arg ...]]\n");
> }
>
> --
> 2.8.3
>
>

This is total bullshit: it is less readable and it makes no sense to
optimize this case. Please fix real bugs.
Received on Sat Oct 29 2016 - 11:40:24 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 29 2016 - 11:48:13 CEST