optimization: don't add intermediate closure addrs to closure; we ignore them during reach anyway. saves time/space.
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6840]
This commit is contained in:
parent
27d9f25ec2
commit
62aa952f34
|
@ -195,7 +195,6 @@ processOneChar:
|
||||||
ThreadState t = new ThreadState(ip, alt, context);
|
ThreadState t = new ThreadState(ip, alt, context);
|
||||||
//System.out.println("add to closure "+ip+" "+closure);
|
//System.out.println("add to closure "+ip+" "+closure);
|
||||||
if ( closure.contains(t) ) return;
|
if ( closure.contains(t) ) return;
|
||||||
closure.add(t);
|
|
||||||
short opcode = code[ip];
|
short opcode = code[ip];
|
||||||
ip++; // move to next instruction or first byte of operand
|
ip++; // move to next instruction or first byte of operand
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
@ -207,6 +206,7 @@ processOneChar:
|
||||||
case Bytecode.LABEL :
|
case Bytecode.LABEL :
|
||||||
case Bytecode.SAVE :
|
case Bytecode.SAVE :
|
||||||
// see through them for closure ops
|
// see through them for closure ops
|
||||||
|
closure.add(t); // add to closure; need to execute during reach
|
||||||
ip += 2;
|
ip += 2;
|
||||||
addToClosure(closure, ip, alt, context); // do closure past SAVE
|
addToClosure(closure, ip, alt, context); // do closure past SAVE
|
||||||
break;
|
break;
|
||||||
|
@ -227,6 +227,7 @@ processOneChar:
|
||||||
// accept is just a ret if we have a stack;
|
// accept is just a ret if we have a stack;
|
||||||
// i.e., don't stop; someone called us and we need to use their
|
// i.e., don't stop; someone called us and we need to use their
|
||||||
// accept, not this one
|
// accept, not this one
|
||||||
|
closure.add(t); // add to closure; need to execute during reach
|
||||||
case Bytecode.RET :
|
case Bytecode.RET :
|
||||||
if ( context != NFAStack.EMPTY ) {
|
if ( context != NFAStack.EMPTY ) {
|
||||||
addToClosure(closure, context.returnAddr, alt, context.parent);
|
addToClosure(closure, context.returnAddr, alt, context.parent);
|
||||||
|
@ -241,6 +242,11 @@ processOneChar:
|
||||||
addToClosure(closure, ip+4, alt, context);
|
addToClosure(closure, ip+4, alt, context);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default :
|
||||||
|
// optimization: only add edges of closure to closure list; reduces what we walk later
|
||||||
|
// we don't want to have to ignore CALL, RET, etc... later
|
||||||
|
closure.add(t);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue