]> git.draconx.ca Git - cdecl99.git/commitdiff
cdecl99: Simplify main command output.
authorNick Bowler <nbowler@draconx.ca>
Fri, 12 Jan 2024 05:27:09 +0000 (00:27 -0500)
committerNick Bowler <nbowler@draconx.ca>
Fri, 12 Jan 2024 05:38:35 +0000 (00:38 -0500)
When the separate command functions were merged everything was combined
into one relatively complex printf call.  Profiling on GNU/Linux showed
a surprising amount of time spent printing.

Restructure the code to just print the two cases separately.  The result
is easier to understand, compiles to less code, and is slightly faster,
so what's not to like?

src/commands.c

index 429ba852efff70b67470722e2cd8b012a68c9fde..a80fe766040dde18cb8d1ded233c4b2e7e2fc381 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Main command implementation routines for cdecl99.
- * Copyright © 2011-2012, 2020-2021, 2023 Nick Bowler
+ * Copyright © 2011-2012, 2020-2021, 2023-2024 Nick Bowler
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -88,7 +88,6 @@ int run_command_cdecl(const char *s, int input_mode, int output_mode)
 
        for (i = parse; i; i = i->next) {
                const char *str;
-               int no_nl = 0;
 
                if (!(str = do_render(i, output_mode)))
                        goto out;
@@ -99,10 +98,10 @@ int run_command_cdecl(const char *s, int input_mode, int output_mode)
                 */
                if (output_mode == OUTPUT_C && i->next) {
                        i->next->specifiers = NULL;
-                       no_nl = 1;
+                       printf("%s, ", str);
+               } else {
+                       puts(str);
                }
-
-               printf(", %s%s" + 2*!!i->specifiers, str, "\n" + no_nl);
        }
 
        ret = 0;