* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)names.c 5.2 (Berkeley) %G%";
static char rcsid
[] = "$Header: names.c,v 1.2 87/03/26 20:16:59 donn Exp $";
* Name are the internal representation for identifiers.
* A hash table is used to map identifiers to names.
typedef struct Name
*Name
;
* Inline (for speed) function to return the identifier (string)
* associated with a name. Because C cannot support both inlines
* and data hiding at the same time, the Name structure must be
* publicly visible. It is not used explicitly, however, outside of this file.
#define ident(n) ((n == nil) ? "(noname)" : n->identifier)
* The hash table is a power of two, in order to make hashing faster.
* Using a non-prime is ok since we use chaining instead of re-hashing.
#define HASHTABLESIZE 8192
private Name nametable
[HASHTABLESIZE
];
* Names are allocated in large chunks to avoid calls to malloc
* and to cluster names in memory so that tracing hash chains
* doesn't cause many a page fault.
typedef struct Namepool
{
struct Name name
[CHUNKSIZE
];
struct Namepool
*prevpool
;
private Namepool namepool
= nil
;
private Integer nleft
= 0;
* Given an identifier, convert it to a name.
* If it's not in the hash table, then put it there.
* The second argument specifies whether the string should be copied
* into newly allocated space if not found.
* This routine is time critical when starting up the debugger
public Name
identname(s
, isallocated
)
for (p
= s
; *p
!= '\0'; p
++) {
* Now we know that name hasn't been found,
* so we allocate a name, store the identifier, and
* enter it in the hash table.
newpool
->prevpool
= namepool
;
n
= &(namepool
->name
[nleft
]);
/* this case doesn't happen very often */
n
->identifier
= newarr(char, strlen(s
) + 1);
* Deallocate the name table.
for (i
= 0; i
< HASHTABLESIZE
; i
++) {