From b15a6d47dc666d660c9cb5b7b75337492896902c Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Fri, 8 Mar 2019 22:00:30 +0100 Subject: [PATCH] use a hash table to parse temporaries --- parse.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/parse.c b/parse.c index 3c4200e..fd3f609 100644 --- a/parse.c +++ b/parse.c @@ -102,6 +102,7 @@ static char *kwmap[Ntok] = { }; enum { + TMask = 16383, /* for temps hash */ BMask = 8191, /* for blocks hash */ K = 3233235, /* found using tools/lexh.c */ @@ -122,6 +123,7 @@ static struct { static int lnum; static Fn *curf; +static int tmph[TMask+1]; static Phi **plink; static Blk *curb; static Blk **blink; @@ -346,11 +348,19 @@ expect(int t) static Ref tmpref(char *v) { - int t; + int t, *h; - for (t=Tmp0; tntmp; t++) - if (strcmp(v, curf->tmp[t].name) == 0) + h = &tmph[hash(v) & TMask]; + t = *h; + if (t) { + if (strcmp(curf->tmp[t].name, v) == 0) return TMP(t); + for (t=curf->ntmp-1; t>=Tmp0; t--) + if (strcmp(curf->tmp[t].name, v) == 0) + return TMP(t); + } + t = curf->ntmp; + *h = t; newtmp(0, Kx, curf); strcpy(curf->tmp[t].name, v); return TMP(t); @@ -810,6 +820,7 @@ parsefn(int export) b->dlink = 0; /* was trashed by findblk() */ for (i=0; i