svn commit: trunk/busybox/shell

vda at busybox.net vda at busybox.net
Sat Jul 14 18:45:38 UTC 2007


Author: vda
Date: 2007-07-14 11:45:37 -0700 (Sat, 14 Jul 2007)
New Revision: 19088

Log:
ash: small size optimization
function                                             old     new   delta
makejob                                              263     270      +7
setjobctl                                            328     332      +4
jobscmd                                               96      94      -2
stoppedjobs                                           53      50      -3
jobctl                                                 4       1      -3
job_warning                                            4       1      -3
forkshell                                            644     641      -3
cmdloop                                              422     409     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/6 up/down: 11/-27)            Total: -16 bytes
   text    data     bss     dec     hex filename
 675392    2740   13968  692100   a8f84 busybox_old
 675380    2740   13968  692088   a8f78 busybox_unstripped



Modified:
   trunk/busybox/shell/ash.c


Changeset:
Modified: trunk/busybox/shell/ash.c
===================================================================
--- trunk/busybox/shell/ash.c	2007-07-14 14:52:24 UTC (rev 19087)
+++ trunk/busybox/shell/ash.c	2007-07-14 18:45:37 UTC (rev 19088)
@@ -3141,20 +3141,18 @@
 };
 
 static pid_t backgndpid;        /* pid of last background process */
-static int job_warning;         /* user was warned about stopped jobs */
-#if JOBS
-static int jobctl;              /* true if doing job control */
-#endif
+static smallint job_warning;    /* user was warned about stopped jobs (can be 2, 1 or 0). */
 
 static struct job *makejob(union node *, int);
 static int forkshell(struct job *, union node *, int);
 static int waitforjob(struct job *);
 
-#if ! JOBS
-#define setjobctl(on)   /* do nothing */
+#if !JOBS
+enum { jobctl = 0 };
+#define setjobctl(on) do {} while (0)
 #else
+static smallint jobctl;              /* true if doing job control */
 static void setjobctl(int);
-static void showjobs(FILE *, int);
 #endif
 
 /*
@@ -3836,11 +3834,32 @@
 	}
 }
 
+/*
+ * Print a list of jobs.  If "change" is nonzero, only print jobs whose
+ * statuses have changed since the last call to showjobs.
+ */
+static void
+showjobs(FILE *out, int mode)
+{
+	struct job *jp;
+
+	TRACE(("showjobs(%x) called\n", mode));
+
+	/* If not even one one job changed, there is nothing to do */
+	while (dowait(DOWAIT_NORMAL, NULL) > 0)
+		continue;
+
+	for (jp = curjob; jp; jp = jp->prev_job) {
+		if (!(mode & SHOW_CHANGED) || jp->changed) {
+			showjob(out, jp, mode);
+		}
+	}
+}
+
 static int
 jobscmd(int argc, char **argv)
 {
 	int mode, m;
-	FILE *out;
 
 	mode = 0;
 	while ((m = nextopt("lp"))) {
@@ -3850,38 +3869,16 @@
 			mode = SHOW_PGID;
 	}
 
-	out = stdout;
 	argv = argptr;
 	if (*argv) {
 		do
-			showjob(out, getjob(*argv,0), mode);
+			showjob(stdout, getjob(*argv,0), mode);
 		while (*++argv);
 	} else
-		showjobs(out, mode);
+		showjobs(stdout, mode);
 
 	return 0;
 }
-
-/*
- * Print a list of jobs.  If "change" is nonzero, only print jobs whose
- * statuses have changed since the last call to showjobs.
- */
-static void
-showjobs(FILE *out, int mode)
-{
-	struct job *jp;
-
-	TRACE(("showjobs(%x) called\n", mode));
-
-	/* If not even one one job changed, there is nothing to do */
-	while (dowait(DOWAIT_NORMAL, NULL) > 0)
-		continue;
-
-	for (jp = curjob; jp; jp = jp->prev_job) {
-		if (!(mode & SHOW_CHANGED) || jp->changed)
-			showjob(out, jp, mode);
-	}
-}
 #endif /* JOBS */
 
 static int
@@ -4043,6 +4040,8 @@
 	}
 	memset(jp, 0, sizeof(*jp));
 #if JOBS
+	/* jp->jobctl is a bitfield.
+	 * "jp->jobctl |= jobctl" likely to give awful code */
 	if (jobctl)
 		jp->jobctl = 1;
 #endif
@@ -10883,7 +10882,8 @@
 			}
 			numeof++;
 		} else if (nflag == 0) {
-			job_warning = (job_warning == 2) ? 1 : 0;
+			/* job_warning can only be 2,1,0. Here 2->1, 1/0->0 */
+			job_warning >>= 1;
 			numeof = 0;
 			evaltree(n, 0);
 		}




More information about the busybox-cvs mailing list