Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): extract percentage calculation out of ...



details:   https://anonhg.NetBSD.org/src/rev/b1efe4389abf
branches:  trunk
changeset: 1013191:b1efe4389abf
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 22 15:55:22 2020 +0000

description:
make(1): extract percentage calculation out of Dir_PrintDirectories

diffstat:

 usr.bin/make/dir.c |  15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diffs (49 lines):

diff -r b05e6b3ee98c -r b1efe4389abf usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sat Aug 22 15:46:28 2020 +0000
+++ b/usr.bin/make/dir.c        Sat Aug 22 15:55:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.104 2020/08/22 15:43:32 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.105 2020/08/22 15:55:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.104 2020/08/22 15:43:32 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.105 2020/08/22 15:55:22 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c      8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.104 2020/08/22 15:43:32 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.105 2020/08/22 15:55:22 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1771,6 +1771,12 @@
     }
 }
 
+static int
+percentage(int num, int den)
+{
+    return den != 0 ? num * 100 / den : 0;
+}
+
 /********** DEBUG INFO **********/
 void
 Dir_PrintDirectories(void)
@@ -1782,8 +1788,7 @@
     fprintf(debug_file,
            "# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n",
            hits, misses, nearmisses, bigmisses,
-           (hits + bigmisses + nearmisses ?
-            hits * 100 / (hits + bigmisses + nearmisses) : 0));
+           percentage(hits, hits + bigmisses + nearmisses));
     fprintf(debug_file, "# %-20s referenced\thits\n", "directory");
     if (Lst_Open(openDirectories) == SUCCESS) {
        while ((ln = Lst_NextS(openDirectories)) != NULL) {



Home | Main Index | Thread Index | Old Index