changeset 122:ee49aa0dc731

Show the compiler how to optimize out the option parsing logic when nothing is using it.
author Rob Landley <rob@landley.net>
date Fri, 01 Jun 2007 14:31:45 -0400
parents 933766b0bd4b
children 81a324ef9167
files main.c
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Fri Jun 01 13:41:24 2007 -0400
+++ b/main.c	Fri Jun 01 14:31:45 2007 -0400
@@ -50,6 +50,18 @@
 	}
 }
 
+// Figure out whether or not anything is using the option parsing logic,
+// because the compiler can't figure out whether or not to optimize it away
+// on its' own.
+
+#undef NEWTOY
+#undef OLDTOY
+#define NEWTOY(name, opts, flags) opts ||
+#define OLDTOY(name, oldname, opts, flags) opts ||
+static const NEED_OPTIONS =
+#include "toys/toylist.h"
+0;  // Ends the opts || opts || opts...
+
 void toy_init(struct toy_list *which, char *argv[])
 {
 	// Free old toys contents here?
@@ -57,7 +69,7 @@
 	toys.which = which;
 	toys.argv = argv;
 	toys.exitval = 1;
-	if (which->options) get_optflags();
+	if (NEED_OPTIONS && which->options) get_optflags();
 	else toys.optargs = argv+1;
 }