Skip to content
Snippets Groups Projects
Commit ee08c4af authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Optimized the state queue some more.

Compiling language.yacc has now gone from ~300 to ~110 seconds.
Still needs more optimizations though.

Rev: lib/modules/LR.pmod/parser.pike:1.5
parent 3a6198c7
No related branches found
No related tags found
No related merge requests found
/* /*
* $Id: parser.pike,v 1.4 1998/11/12 01:30:43 grubba Exp $ * $Id: parser.pike,v 1.5 1998/11/12 02:22:07 grubba Exp $
* *
* A BNF-grammar in Pike. * A BNF-grammar in Pike.
* Compiles to a LALR(1) state-machine. * Compiles to a LALR(1) state-machine.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
//. //.
//. File: parser.pike //. File: parser.pike
//. RCSID: $Id: parser.pike,v 1.4 1998/11/12 01:30:43 grubba Exp $ //. RCSID: $Id: parser.pike,v 1.5 1998/11/12 02:22:07 grubba Exp $
//. Author: Henrik Grubbström (grubba@infovav.se) //. Author: Henrik Grubbström (grubba@infovav.se)
//. //.
//. Synopsis: LALR(1) parser and compiler. //. Synopsis: LALR(1) parser and compiler.
...@@ -73,6 +73,10 @@ class state_queue { ...@@ -73,6 +73,10 @@ class state_queue {
//. The queue/set itself. //. The queue/set itself.
array(object(LR.kernel)) arr=allocate(64); array(object(LR.kernel)) arr=allocate(64);
//. + members
//. Hashes of the states that are members.
mapping(string:int) members = ([]);
//. - memberp //. - memberp
//. Returns the index of the state in arr if present. //. Returns the index of the state in arr if present.
//. Returns -1 on failure. //. Returns -1 on failure.
...@@ -80,14 +84,13 @@ class state_queue { ...@@ -80,14 +84,13 @@ class state_queue {
//. State to search for. //. State to search for.
int|object(LR.kernel) memberp(object(LR.kernel) state) int|object(LR.kernel) memberp(object(LR.kernel) state)
{ {
int j; if (!state->kernel_hash) {
state->make_kernel_hash();
for (j = 0; j<tail; j++) { }
if (state->equalp(arr[j])) { if (zero_type(members[state->kernel_hash])) {
return(j); return(-1);
}
} }
return(-1); return(members[state->kernel_hash]);
} }
//. - push_if_new //. - push_if_new
...@@ -104,6 +107,7 @@ class state_queue { ...@@ -104,6 +107,7 @@ class state_queue {
if (tail == sizeof(arr)) { if (tail == sizeof(arr)) {
arr += allocate(tail); arr += allocate(tail);
} }
members[state->kernel_hash] = tail;
arr[tail++] = state; arr[tail++] = state;
return(state); return(state);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment