Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/ps Don't bother using variables whose value is never cha...



details:   https://anonhg.NetBSD.org/src/rev/1106166c10b8
branches:  trunk
changeset: 328849:1106166c10b8
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Apr 20 23:31:40 2014 +0000

description:
Don't bother using variables whose value is never changed from the
initialization value.

diffstat:

 bin/ps/ps.c |  59 +++++++++++++++++++++++++++++------------------------------
 1 files changed, 29 insertions(+), 30 deletions(-)

diffs (111 lines):

diff -r 9a032c24508b -r 1106166c10b8 bin/ps/ps.c
--- a/bin/ps/ps.c       Sun Apr 20 22:48:59 2014 +0000
+++ b/bin/ps/ps.c       Sun Apr 20 23:31:40 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ps.c,v 1.80 2014/02/19 20:42:14 dsl Exp $      */
+/*     $NetBSD: ps.c,v 1.81 2014/04/20 23:31:40 dholland Exp $ */
 
 /*
  * Copyright (c) 2000-2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
 #if 0
 static char sccsid[] = "@(#)ps.c       8.4 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: ps.c,v 1.80 2014/02/19 20:42:14 dsl Exp $");
+__RCSID("$NetBSD: ps.c,v 1.81 2014/04/20 23:31:40 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -199,7 +199,7 @@
        struct kinfo_lwp *kl, *l;
        int ch, i, j, fmt, lineno, nentries, nlwps;
        long long flag;
-       int prtheader, wflag, what, xflg, mode, showlwps;
+       int prtheader, wflag, what, xflg, showlwps;
        char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX];
        char *ttname;
 
@@ -221,7 +221,7 @@
        what = KERN_PROC_UID;
        flag = myuid = getuid();
        memf = nlistf = swapf = NULL;
-       mode = PRINTMODE;
+
        while ((ch = getopt(argc, argv, GETOPTSTR)) != -1)
                switch((char)ch) {
                case 'A':
@@ -421,33 +421,32 @@
         * "setwidth" mode to determine the widest element of
         * the column.
         */
-       if (mode == PRINTMODE)
-               for (i = 0; i < nentries; i++) {
-                       struct kinfo_proc2 *ki = &kinfo[i];
+
+       for (i = 0; i < nentries; i++) {
+               struct kinfo_proc2 *ki = &kinfo[i];
 
-                       if (xflg == 0 && (ki->p_tdev == (uint32_t)NODEV ||
-                           (ki->p_flag & P_CONTROLT) == 0))
-                               continue;
+               if (xflg == 0 && (ki->p_tdev == (uint32_t)NODEV ||
+                   (ki->p_flag & P_CONTROLT) == 0))
+                       continue;
 
-                       kl = kvm_getlwps(kd, ki->p_pid, ki->p_paddr,
-                           sizeof(struct kinfo_lwp), &nlwps);
-                       if (kl == 0)
-                               nlwps = 0;
-                       if (showlwps == 0) {
-                               l = pick_representative_lwp(ki, kl, nlwps);
-                               SIMPLEQ_FOREACH(vent, &displaylist, next)
-                                       OUTPUT(vent, ki, l, WIDTHMODE);
-                       } else {
-                               /* The printing is done with the loops
-                                * reversed, but here we don't need that,
-                                * and this improves the code locality a bit.
-                                */
-                               SIMPLEQ_FOREACH(vent, &displaylist, next)
-                                       for (j = 0; j < nlwps; j++)
-                                               OUTPUT(vent, ki, &kl[j],
-                                                   WIDTHMODE);
-                       }
+               kl = kvm_getlwps(kd, ki->p_pid, ki->p_paddr,
+                   sizeof(struct kinfo_lwp), &nlwps);
+               if (kl == 0)
+                       nlwps = 0;
+               if (showlwps == 0) {
+                       l = pick_representative_lwp(ki, kl, nlwps);
+                       SIMPLEQ_FOREACH(vent, &displaylist, next)
+                               OUTPUT(vent, ki, l, WIDTHMODE);
+               } else {
+                       /* The printing is done with the loops
+                        * reversed, but here we don't need that,
+                        * and this improves the code locality a bit.
+                        */
+                       SIMPLEQ_FOREACH(vent, &displaylist, next)
+                               for (j = 0; j < nlwps; j++)
+                                       OUTPUT(vent, ki, &kl[j], WIDTHMODE);
                }
+       }
        /*
         * Print header - AFTER determining process field widths.
         * printheader() also adds up the total width of all
@@ -471,7 +470,7 @@
                if (showlwps == 0) {
                        l = pick_representative_lwp(ki, kl, nlwps);
                        SIMPLEQ_FOREACH(vent, &displaylist, next) {
-                               OUTPUT(vent, ki, l, mode);
+                               OUTPUT(vent, ki, l, PRINTMODE);
                                if (SIMPLEQ_NEXT(vent, next) != NULL)
                                        (void)putchar(' ');
                        }
@@ -484,7 +483,7 @@
                } else {
                        for (j = 0; j < nlwps; j++) {
                                SIMPLEQ_FOREACH(vent, &displaylist, next) {
-                                       OUTPUT(vent, ki, &kl[j], mode);
+                                       OUTPUT(vent, ki, &kl[j], PRINTMODE);
                                        if (SIMPLEQ_NEXT(vent, next) != NULL)
                                                (void)putchar(' ');
                                }



Home | Main Index | Thread Index | Old Index