From bcb141e5d0e26e3745d5f6ec2119f720ee4f2bb4 Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Wed, 15 Sep 1999 22:51:05 +0000 Subject: [PATCH] Reuse the Hash_Entry `name' field to store the variable name when we can (i.e., everything except environment variables, which aren't stored in hash tables). While we're here, inline the body of VarDelete into Var_Delete since it's the only caller and it's just simpler that way when v->name can share storage with the hash entry and may not need to be freed separately. Speeds up the infamous libc build benchhmark maybe 1% on PIII, 4% on alpha pc164 Suggested by Perry Metzger. --- usr.bin/make/var.c | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 470a46468862..a419f1888fa8 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.36 1999/09/15 02:56:35 mycroft Exp $ */ +/* $NetBSD: var.c,v 1.37 1999/09/15 22:51:05 sommerfeld Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -39,14 +39,14 @@ */ #ifdef MAKE_BOOTSTRAP -static char rcsid[] = "$NetBSD: var.c,v 1.36 1999/09/15 02:56:35 mycroft Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.37 1999/09/15 22:51:05 sommerfeld Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: var.c,v 1.36 1999/09/15 02:56:35 mycroft Exp $"); +__RCSID("$NetBSD: var.c,v 1.37 1999/09/15 22:51:05 sommerfeld Exp $"); #endif #endif /* not lint */ #endif @@ -180,7 +180,6 @@ typedef struct { static Var *VarFind __P((char *, GNode *, int)); static void VarAdd __P((char *, char *, GNode *)); -static void VarDelete __P((ClientData)); static Boolean VarHead __P((char *, Boolean, Buffer, ClientData)); static Boolean VarTail __P((char *, Boolean, Buffer, ClientData)); static Boolean VarSuffix __P((char *, Boolean, Buffer, ClientData)); @@ -344,8 +343,6 @@ VarAdd (name, val, ctxt) v = (Var *) emalloc (sizeof (Var)); - v->name = estrdup (name); - len = val ? strlen(val) : 0; v->val = Buf_Init(len+1); Buf_AddBytes(v->val, len, (Byte *)val); @@ -354,36 +351,12 @@ VarAdd (name, val, ctxt) h = Hash_CreateEntry (&ctxt->context, name, NULL); Hash_SetValue(h, v); + v->name = h->name; if (DEBUG(VAR)) { printf("%s:%s = %s\n", ctxt->name, name, val); } } - -/*- - *----------------------------------------------------------------------- - * VarDelete -- - * Delete a variable and all the space associated with it. - * - * Results: - * None - * - * Side Effects: - * None - *----------------------------------------------------------------------- - */ -static void -VarDelete(vp) - ClientData vp; -{ - Var *v = (Var *) vp; - free(v->name); - Buf_Destroy(v->val, TRUE); - free((Address) v); -} - - - /*- *----------------------------------------------------------------------- * Var_Delete -- @@ -412,8 +385,11 @@ Var_Delete(name, ctxt) register Var *v; v = (Var *)Hash_GetValue(ln); + if (v->name != ln->name) + free(v->name); Hash_DeleteEntry(&ctxt->context, ln); - VarDelete((ClientData) v); + Buf_Destroy(v->val, TRUE); + free((Address) v); } }