From 62aa952f34ef158d1a85970825959e281f9b28ff Mon Sep 17 00:00:00 2001 From: parrt <parrt@antlr.org> Date: Wed, 5 May 2010 11:22:22 -0800 Subject: [PATCH] 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] --- runtime/Java/src/org/antlr/v4/runtime/nfa/NFA.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/nfa/NFA.java b/runtime/Java/src/org/antlr/v4/runtime/nfa/NFA.java index 3634e89d5..41a377a36 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/nfa/NFA.java +++ b/runtime/Java/src/org/antlr/v4/runtime/nfa/NFA.java @@ -195,7 +195,6 @@ processOneChar: ThreadState t = new ThreadState(ip, alt, context); //System.out.println("add to closure "+ip+" "+closure); if ( closure.contains(t) ) return; - closure.add(t); short opcode = code[ip]; ip++; // move to next instruction or first byte of operand switch (opcode) { @@ -207,6 +206,7 @@ processOneChar: case Bytecode.LABEL : case Bytecode.SAVE : // see through them for closure ops + closure.add(t); // add to closure; need to execute during reach ip += 2; addToClosure(closure, ip, alt, context); // do closure past SAVE break; @@ -227,6 +227,7 @@ processOneChar: // accept is just a ret if we have a stack; // i.e., don't stop; someone called us and we need to use their // accept, not this one + closure.add(t); // add to closure; need to execute during reach case Bytecode.RET : if ( context != NFAStack.EMPTY ) { addToClosure(closure, context.returnAddr, alt, context.parent); @@ -241,6 +242,11 @@ processOneChar: addToClosure(closure, ip+4, alt, context); } 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; } }