mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
switch from linked list to hash table for traced macros.
speeds up recent autoconf somewhat, since it traces a large set of individual macro. (more rework of m4 internal interfaces to unify lookup tables in order) okay fries@
This commit is contained in:
parent
9d0b46bce1
commit
3ed6d6dce4
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: extern.h,v 1.31 2003/06/03 02:56:10 millert Exp $ */
|
||||
/* $OpenBSD: extern.h,v 1.32 2003/06/12 14:36:43 espie Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
|
||||
|
||||
/*-
|
||||
@ -123,6 +123,7 @@ extern void finish_trace(size_t);
|
||||
extern int traced_macros;
|
||||
extern void set_trace_flags(const char *);
|
||||
extern FILE *traceout;
|
||||
extern void init_trace(void);
|
||||
|
||||
extern ndptr hashtab[]; /* hash table for macros etc. */
|
||||
extern stae *mstack; /* stack of m4 machine */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: main.c,v 1.56 2003/06/10 22:20:48 deraadt Exp $ */
|
||||
/* $OpenBSD: main.c,v 1.57 2003/06/12 14:36:43 espie Exp $ */
|
||||
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
|
||||
|
||||
/*-
|
||||
@ -43,7 +43,7 @@ static char copyright[] =
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
static char rcsid[] = "$OpenBSD: main.c,v 1.56 2003/06/10 22:20:48 deraadt Exp $";
|
||||
static char rcsid[] = "$OpenBSD: main.c,v 1.57 2003/06/12 14:36:43 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -180,6 +180,7 @@ main(int argc, char *argv[])
|
||||
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
||||
signal(SIGINT, onintr);
|
||||
|
||||
init_trace();
|
||||
initkwds();
|
||||
initspaces();
|
||||
STACKMAX = INITSTACKMAX;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: mdef.h,v 1.23 2003/06/03 02:56:10 millert Exp $ */
|
||||
/* $OpenBSD: mdef.h,v 1.24 2003/06/12 14:36:43 espie Exp $ */
|
||||
/* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */
|
||||
|
||||
/*
|
||||
@ -35,6 +35,12 @@
|
||||
* @(#)mdef.h 8.1 (Berkeley) 6/6/93
|
||||
*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
# define UNUSED
|
||||
#endif
|
||||
|
||||
#define MACRTYPE 1
|
||||
#define DEFITYPE 2
|
||||
#define EXPRTYPE 3
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: trace.c,v 1.6 2002/04/26 16:15:16 espie Exp $ */
|
||||
/* $OpenBSD: trace.c,v 1.7 2003/06/12 14:36:43 espie Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2001 Marc Espie.
|
||||
*
|
||||
@ -29,6 +29,7 @@
|
||||
#include <stdio.h>
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <ohash.h>
|
||||
#include "mdef.h"
|
||||
#include "stdd.h"
|
||||
#include "extern.h"
|
||||
@ -48,35 +49,70 @@ int traced_macros = 0;
|
||||
#define TRACE_INPUT 256 /* not implemented yet */
|
||||
#define TRACE_ALL 512
|
||||
|
||||
static struct t {
|
||||
struct t *next;
|
||||
char *name;
|
||||
struct t {
|
||||
int on;
|
||||
} *l;
|
||||
char name[1];
|
||||
};
|
||||
|
||||
|
||||
static unsigned int letter_to_flag(int);
|
||||
static void print_header(struct input_file *);
|
||||
static struct t *find_trace_entry(const char *);
|
||||
static int frame_level(void);
|
||||
static void *hash_alloc(size_t, void *);
|
||||
static void hash_free(void *, size_t, void *);
|
||||
static void *element_alloc(size_t, void *);
|
||||
|
||||
static unsigned int flags = TRACE_QUOTE | TRACE_EXPANSION;
|
||||
|
||||
static struct t *
|
||||
find_trace_entry(const char *name)
|
||||
{
|
||||
struct t *n;
|
||||
static struct ohash_info trace_info = {
|
||||
offsetof(struct t, name),
|
||||
NULL, hash_alloc, hash_free, element_alloc };
|
||||
|
||||
for (n = l; n != NULL; n = n->next)
|
||||
if (STREQ(n->name, name))
|
||||
return n;
|
||||
return NULL;
|
||||
static struct ohash trace_hash;
|
||||
|
||||
/* Support routines for hash tables. */
|
||||
void *
|
||||
hash_alloc(s, u)
|
||||
size_t s;
|
||||
void *u UNUSED;
|
||||
{
|
||||
void *storage = xalloc(s);
|
||||
if (storage)
|
||||
memset(storage, 0, s);
|
||||
return storage;
|
||||
}
|
||||
|
||||
void
|
||||
hash_free(p, s, u)
|
||||
void *p;
|
||||
size_t s UNUSED;
|
||||
void *u UNUSED;
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
void *
|
||||
element_alloc(s, u)
|
||||
size_t s;
|
||||
void *u UNUSED;
|
||||
{
|
||||
return xalloc(s);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
init_trace()
|
||||
{
|
||||
ohash_init(&trace_hash, 5, &trace_info);
|
||||
}
|
||||
|
||||
void
|
||||
mark_traced(const char *name, int on)
|
||||
{
|
||||
struct t *n, *n2;
|
||||
struct t *n;
|
||||
unsigned int i;
|
||||
const char *end = NULL;
|
||||
|
||||
traced_macros = 1;
|
||||
|
||||
@ -87,19 +123,15 @@ mark_traced(const char *name, int on)
|
||||
flags &= ~TRACE_ALL;
|
||||
traced_macros = 0;
|
||||
}
|
||||
for (n = l; n != NULL; n = n2) {
|
||||
n2 = n->next;
|
||||
free(n->name);
|
||||
for (n = ohash_first(&trace_hash, &i); n != NULL;
|
||||
n = ohash_next(&trace_hash, &i))
|
||||
free(n);
|
||||
}
|
||||
l = NULL;
|
||||
} else {
|
||||
n = find_trace_entry(name);
|
||||
i = ohash_qlookupi(&trace_hash, name, &end);
|
||||
n = ohash_find(&trace_hash, i);
|
||||
if (n == NULL) {
|
||||
n = xalloc(sizeof(struct t));
|
||||
n->name = xstrdup(name);
|
||||
n->next = l;
|
||||
l = n;
|
||||
n = ohash_create_entry(&trace_info, name, &end);
|
||||
ohash_insert(&trace_hash, i, n);
|
||||
}
|
||||
n->on = on;
|
||||
}
|
||||
@ -110,10 +142,11 @@ is_traced(const char *name)
|
||||
{
|
||||
struct t *n;
|
||||
|
||||
for (n = l; n != NULL; n = n->next)
|
||||
if (STREQ(n->name, name))
|
||||
return n->on;
|
||||
return (flags & TRACE_ALL) ? 1 : 0;
|
||||
n = ohash_find(&trace_hash, ohash_qlookup(&trace_hash, name));
|
||||
if (n)
|
||||
return n->on;
|
||||
else
|
||||
return (flags & TRACE_ALL) ? 1 : 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user