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 the fds[] realloc O(n). Also make the ret...



details:   https://anonhg.NetBSD.org/src/rev/13d02106fb5b
branches:  trunk
changeset: 500122:13d02106fb5b
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Tue Dec 05 21:57:20 2000 +0000

description:
Make the fds[] realloc O(n).  Also make the rethreading a lot simpler.

diffstat:

 usr.bin/make/job.c |  36 ++++++++++++------------------------
 1 files changed, 12 insertions(+), 24 deletions(-)

diffs (82 lines):

diff -r 37b10122bae4 -r 13d02106fb5b usr.bin/make/job.c
--- a/usr.bin/make/job.c        Tue Dec 05 21:57:13 2000 +0000
+++ b/usr.bin/make/job.c        Tue Dec 05 21:57:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.38 2000/12/05 15:28:55 sommerfeld Exp $      */
+/*     $NetBSD: job.c,v 1.39 2000/12/05 21:57:20 mycroft Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -39,14 +39,14 @@
  */
 
 #ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: job.c,v 1.38 2000/12/05 15:28:55 sommerfeld Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.39 2000/12/05 21:57:20 mycroft Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c      8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.38 2000/12/05 15:28:55 sommerfeld Exp $");
+__RCSID("$NetBSD: job.c,v 1.39 2000/12/05 21:57:20 mycroft Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -253,7 +253,7 @@
 static void clearfd __P((Job *));
 static int readyfd __P((Job *));
 #define JBSTART 256
-#define JBINCR 256
+#define JBFACTOR 2
 #endif
 #endif
 
@@ -3245,6 +3245,7 @@
 watchfd(job)
     Job *job;
 {
+    int i;
     if (job->inPollfd != NULL)
        Punt("Watching watched job");
     if (fds == NULL) {
@@ -3252,31 +3253,18 @@
        fds = emalloc(sizeof(struct pollfd) * maxfds);
        jobfds = emalloc(sizeof(Job **) * maxfds);
     } else if (nfds == maxfds) {
-       struct pollfd *newfds;
-       maxfds += JBINCR;
-       newfds = erealloc(fds, sizeof(struct pollfd) * maxfds);
+       maxfds *= JBFACTOR;
+       fds = erealloc(fds, sizeof(struct pollfd) * maxfds);
        jobfds = erealloc(jobfds, sizeof(Job **) * maxfds);
-       if (newfds != fds) {
-           /* Re-thread for the new allocated pointer */
-           LstNode ln;
-           if (Lst_Open(jobs) == FAILURE) {
-               Punt("Cannot open job table");
-           }
-           while ((ln = Lst_Next(jobs)) != NILLNODE) {
-               Job *jb = (Job *) Lst_Datum(ln);
-               int i = jb->inPollfd - fds;
-               jb->inPollfd = &newfds[i];
-               jobfds[i] = jb;
-           }
-           Lst_Close(jobs);
-       }
-       fds = newfds;
+       for (i = 0; i < nfds; i++)
+           jobfds[i]->inPollfd = &fds[i];
     }
 
     fds[nfds].fd = job->inPipe;
-    job->inPollfd = &fds[nfds];
+    fds[nfds].events = POLLIN;
     jobfds[nfds] = job;
-    fds[nfds++].events = POLLIN;
+    job->inPollfd = &fds[nfds];
+    nfds++;
 }
 
 static void



Home | Main Index | Thread Index | Old Index