Improved identifier string allocation mechanism
This commit is contained in:
parent
48e0d9825a
commit
e48822da7b
1 changed files with 27 additions and 2 deletions
|
@ -49,6 +49,32 @@ struct idf *idf_hashtable[HASHSIZE];
|
||||||
(variable, selector, structure tag, etc.).
|
(variable, selector, structure tag, etc.).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static struct idf *
|
||||||
|
idf_new(tg, size)
|
||||||
|
register char *tg;
|
||||||
|
register int size;
|
||||||
|
{
|
||||||
|
#define IBUFSIZ 2048
|
||||||
|
static unsigned int icnt;
|
||||||
|
static char *ip;
|
||||||
|
register char *p;
|
||||||
|
register struct idf *id = new_idf();
|
||||||
|
|
||||||
|
if (size > icnt) {
|
||||||
|
icnt = size > IBUFSIZ ? size : IBUFSIZ;
|
||||||
|
p = malloc(icnt); /* yes, malloc, not Malloc */
|
||||||
|
if (! p) p = Malloc(size);
|
||||||
|
}
|
||||||
|
else p = ip;
|
||||||
|
icnt -= size;
|
||||||
|
id->id_text = p;
|
||||||
|
while (size--) {
|
||||||
|
*p++ = *tg++;
|
||||||
|
}
|
||||||
|
ip = p;
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
struct idf *
|
struct idf *
|
||||||
idf_hashed(tg, size, hc)
|
idf_hashed(tg, size, hc)
|
||||||
char *tg;
|
char *tg;
|
||||||
|
@ -86,10 +112,9 @@ idf_hashed(tg, size, hc)
|
||||||
hook = ¬ch->next;
|
hook = ¬ch->next;
|
||||||
}
|
}
|
||||||
/* a new struct idf must be inserted at the hook */
|
/* a new struct idf must be inserted at the hook */
|
||||||
notch = new_idf();
|
notch = idf_new(tg, size);
|
||||||
notch->next = *hook;
|
notch->next = *hook;
|
||||||
*hook = notch; /* hooked in */
|
*hook = notch; /* hooked in */
|
||||||
notch->id_text = Salloc(tg, (unsigned) size);
|
|
||||||
#ifndef NOPP
|
#ifndef NOPP
|
||||||
/* notch->id_resmac = 0; */
|
/* notch->id_resmac = 0; */
|
||||||
#endif NOPP
|
#endif NOPP
|
||||||
|
|
Loading…
Add table
Reference in a new issue