Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make Replace the linear variable list in the GNode w...



details:   https://anonhg.NetBSD.org/src/rev/288b85a21d88
branches:  trunk
changeset: 476371:288b85a21d88
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Wed Sep 15 02:56:34 1999 +0000

description:
Replace the linear variable list in the GNode with a hash table.  Gives a
small (~10% on my machine) speedup building libc.
Changes by: perry (+ bug fix and minor change by me)
Reviewed by: mycroft sommerfeld

diffstat:

 usr.bin/make/make.h |   5 +-
 usr.bin/make/targ.c |  10 ++--
 usr.bin/make/var.c  |  94 ++++++++++++++++++++--------------------------------
 3 files changed, 45 insertions(+), 64 deletions(-)

diffs (truncated from 307 to 300 lines):

diff -r 55355dd22ca1 -r 288b85a21d88 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Tue Sep 14 23:48:12 1999 +0000
+++ b/usr.bin/make/make.h       Wed Sep 15 02:56:34 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.21 1998/11/11 19:37:06 christos Exp $       */
+/*     $NetBSD: make.h,v 1.22 1999/09/15 02:56:34 mycroft Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -80,6 +80,7 @@
 #endif
 #include "sprite.h"
 #include "lst.h"
+#include "hash.h"
 #include "config.h"
 #include "buf.h"
 
@@ -159,7 +160,7 @@
     Lst                    successors; /* Nodes that must be made after this one */
     Lst                    preds;      /* Nodes that must be made before this one */
 
-    Lst             context;           /* The local variables */
+    Hash_Table      context;   /* The local variables */
     Lst             commands;          /* Creation commands */
 
     struct _Suff    *suffix;   /* Suffix for the node (determined by
diff -r 55355dd22ca1 -r 288b85a21d88 usr.bin/make/targ.c
--- a/usr.bin/make/targ.c       Tue Sep 14 23:48:12 1999 +0000
+++ b/usr.bin/make/targ.c       Wed Sep 15 02:56:34 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: targ.c,v 1.16 1998/11/11 19:37:06 christos Exp $       */
+/*     $NetBSD: targ.c,v 1.17 1999/09/15 02:56:35 mycroft Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -39,14 +39,14 @@
  */
 
 #ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: targ.c,v 1.16 1998/11/11 19:37:06 christos Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.17 1999/09/15 02:56:35 mycroft Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)targ.c     8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: targ.c,v 1.16 1998/11/11 19:37:06 christos Exp $");
+__RCSID("$NetBSD: targ.c,v 1.17 1999/09/15 02:56:35 mycroft Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -208,7 +208,7 @@
     gn->children =     Lst_Init (FALSE);
     gn->successors =   Lst_Init (FALSE);
     gn->preds =        Lst_Init (FALSE);
-    gn->context =      Lst_Init (FALSE);
+    Hash_InitTable(&gn->context, 0);
     gn->commands =     Lst_Init (FALSE);
     gn->suffix =       NULL;
 
@@ -250,7 +250,7 @@
     Lst_Destroy(gn->children, NOFREE);
     Lst_Destroy(gn->successors, NOFREE);
     Lst_Destroy(gn->preds, NOFREE);
-    Lst_Destroy(gn->context, NOFREE);
+    Hash_DeleteTable(&gn->context);
     Lst_Destroy(gn->commands, NOFREE);
     free((Address)gn);
 }
diff -r 55355dd22ca1 -r 288b85a21d88 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Tue Sep 14 23:48:12 1999 +0000
+++ b/usr.bin/make/var.c        Wed Sep 15 02:56:34 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.35 1999/09/12 00:17:50 christos Exp $        */
+/*     $NetBSD: var.c,v 1.36 1999/09/15 02:56:35 mycroft Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -39,14 +39,14 @@
  */
 
 #ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: var.c,v 1.35 1999/09/12 00:17:50 christos Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.36 1999/09/15 02:56:35 mycroft Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.35 1999/09/12 00:17:50 christos Exp $");
+__RCSID("$NetBSD: var.c,v 1.36 1999/09/15 02:56:35 mycroft Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -135,8 +135,6 @@
 GNode          *VAR_GLOBAL;   /* variables from the makefile */
 GNode          *VAR_CMD;      /* variables defined on the command-line */
 
-static Lst     allVars;      /* List of all variables */
-
 #define FIND_CMD       0x1   /* look in VAR_CMD when searching */
 #define FIND_GLOBAL    0x2   /* look in VAR_GLOBAL as well */
 #define FIND_ENV       0x4   /* look in the environment also */
@@ -180,7 +178,6 @@
 } VarREPattern;
 #endif
 
-static int VarCmp __P((ClientData, ClientData));
 static Var *VarFind __P((char *, GNode *, int));
 static void VarAdd __P((char *, char *, GNode *));
 static void VarDelete __P((ClientData));
@@ -206,28 +203,7 @@
                            ClientData));
 static char *VarSort __P((char *));
 static int VarWordCompare __P((const void *, const void *));
-static int VarPrintVar __P((ClientData, ClientData));
-
-/*-
- *-----------------------------------------------------------------------
- * VarCmp  --
- *     See if the given variable matches the named one. Called from
- *     Lst_Find when searching for a variable of a given name.
- *
- * Results:
- *     0 if they match. non-zero otherwise.
- *
- * Side Effects:
- *     none
- *-----------------------------------------------------------------------
- */
-static int
-VarCmp (v, name)
-    ClientData     v;          /* VAR structure to compare */
-    ClientData     name;       /* name to look for */
-{
-    return (strcmp ((char *) name, ((Var *) v)->name));
-}
+static void VarPrintVar __P((ClientData));
 
 /*-
  *-----------------------------------------------------------------------
@@ -254,7 +230,7 @@
                                 * FIND_ENV set means to look in the
                                 * environment */
 {
-    LstNode            var;
+    Hash_Entry                 *var;
     Var                        *v;
 
        /*
@@ -297,17 +273,17 @@
      * look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order,
      * depending on the FIND_* flags in 'flags'
      */
-    var = Lst_Find (ctxt->context, (ClientData)name, VarCmp);
+    var = Hash_FindEntry (&ctxt->context, name);
 
-    if ((var == NILLNODE) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) {
-       var = Lst_Find (VAR_CMD->context, (ClientData)name, VarCmp);
+    if ((var == NULL) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) {
+       var = Hash_FindEntry (&VAR_CMD->context, name);
     }
-    if (!checkEnvFirst && (var == NILLNODE) && (flags & FIND_GLOBAL) &&
+    if (!checkEnvFirst && (var == NULL) && (flags & FIND_GLOBAL) &&
        (ctxt != VAR_GLOBAL))
     {
-       var = Lst_Find (VAR_GLOBAL->context, (ClientData)name, VarCmp);
+       var = Hash_FindEntry (&VAR_GLOBAL->context, name);
     }
-    if ((var == NILLNODE) && (flags & FIND_ENV)) {
+    if ((var == NULL) && (flags & FIND_ENV)) {
        char *env;
 
        if ((env = getenv (name)) != NULL) {
@@ -326,19 +302,19 @@
        } else if (checkEnvFirst && (flags & FIND_GLOBAL) &&
                   (ctxt != VAR_GLOBAL))
        {
-           var = Lst_Find (VAR_GLOBAL->context, (ClientData)name, VarCmp);
-           if (var == NILLNODE) {
+           var = Hash_FindEntry (&VAR_GLOBAL->context, name);
+           if (var == NULL) {
                return ((Var *) NIL);
            } else {
-               return ((Var *)Lst_Datum(var));
+               return ((Var *)Hash_GetValue(var));
            }
        } else {
            return((Var *)NIL);
        }
-    } else if (var == NILLNODE) {
+    } else if (var == NULL) {
        return ((Var *) NIL);
     } else {
-       return ((Var *) Lst_Datum (var));
+       return ((Var *) Hash_GetValue(var));
     }
 }
 
@@ -364,6 +340,7 @@
 {
     register Var   *v;
     int                  len;
+    Hash_Entry      *h;
 
     v = (Var *) emalloc (sizeof (Var));
 
@@ -375,8 +352,8 @@
 
     v->flags = 0;
 
-    (void) Lst_AtFront (ctxt->context, (ClientData)v);
-    (void) Lst_AtEnd (allVars, (ClientData) v);
+    h = Hash_CreateEntry (&ctxt->context, name, NULL);
+    Hash_SetValue(h, v);
     if (DEBUG(VAR)) {
        printf("%s:%s = %s\n", ctxt->name, name, val);
     }
@@ -425,19 +402,17 @@
     char         *name;
     GNode        *ctxt;
 {
-    LstNode      ln;
+    Hash_Entry           *ln;
 
     if (DEBUG(VAR)) {
        printf("%s:delete %s\n", ctxt->name, name);
     }
-    ln = Lst_Find(ctxt->context, (ClientData)name, VarCmp);
-    if (ln != NILLNODE) {
+    ln = Hash_FindEntry(&ctxt->context, name);
+    if (ln != NULL) {
        register Var      *v;
 
-       v = (Var *)Lst_Datum(ln);
-       Lst_Remove(ctxt->context, ln);
-       ln = Lst_Member(allVars, v);
-       Lst_Remove(allVars, ln);
+       v = (Var *)Hash_GetValue(ln);
+       Hash_DeleteEntry(&ctxt->context, ln);
        VarDelete((ClientData) v);
     }
 }
@@ -525,6 +500,7 @@
     GNode          *ctxt;      /* Context in which this should occur */
 {
     register Var   *v;
+    Hash_Entry    *h;
 
     v = VarFind (name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0);
 
@@ -547,7 +523,8 @@
             * export other variables...)
             */
            v->flags &= ~VAR_FROM_ENV;
-           Lst_AtFront(ctxt->context, (ClientData)v);
+           h = Hash_CreateEntry (&ctxt->context, name, NULL);
+           Hash_SetValue(h, v);
        }
     }
 }
@@ -2450,7 +2427,6 @@
 {
     VAR_GLOBAL = Targ_NewGN ("Global");
     VAR_CMD = Targ_NewGN ("Command");
-    allVars = Lst_Init(FALSE);
 
 }
 
@@ -2458,19 +2434,16 @@
 void
 Var_End ()
 {
-    Lst_Destroy(allVars, VarDelete);
 }
 
 
 /****************** PRINT DEBUGGING INFO *****************/
-static int
-VarPrintVar (vp, dummy)
+static void
+VarPrintVar (vp)
     ClientData vp;
-    ClientData dummy;
 {
     Var    *v = (Var *) vp;
     printf ("%-16s = %s\n", v->name, (char *) Buf_GetAll(v->val, (int *)NULL));
-    return (dummy ? 0 : 0);
 }
 
 /*-
@@ -2483,5 +2456,12 @@
 Var_Dump (ctxt)
     GNode          *ctxt;
 {
-    Lst_ForEach (ctxt->context, VarPrintVar, (ClientData) 0);
+    Hash_Search search;
+    Hash_Entry *h;



Home | Main Index | Thread Index | Old Index