From 11385f792095d0ea333e887e314a947eea4ee758 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 27 Nov 2012 08:46:16 -0600 Subject: [PATCH] Use a zero offset for the first bitset as long as it doesn't force the creation of additional sets --- .../org/antlr/v4/codegen/model/TestSetInline.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tool/src/org/antlr/v4/codegen/model/TestSetInline.java b/tool/src/org/antlr/v4/codegen/model/TestSetInline.java index 1a990b36b..d93c7ec15 100644 --- a/tool/src/org/antlr/v4/codegen/model/TestSetInline.java +++ b/tool/src/org/antlr/v4/codegen/model/TestSetInline.java @@ -44,17 +44,25 @@ public class TestSetInline extends SrcOp { public TestSetInline(OutputModelFactory factory, GrammarAST ast, IntervalSet set) { super(factory, ast); - this.bitsets = createBitsets(factory, set); + Bitset[] withZeroOffset = createBitsets(factory, set, true); + Bitset[] withoutZeroOffset = createBitsets(factory, set, false); + this.bitsets = withZeroOffset.length <= withoutZeroOffset.length ? withZeroOffset : withoutZeroOffset; this.varName = "_la"; } - private static Bitset[] createBitsets(OutputModelFactory factory, IntervalSet set) { + private static Bitset[] createBitsets(OutputModelFactory factory, IntervalSet set, boolean useZeroOffset) { List bitsetList = new ArrayList(); for (int ttype : set.toArray()) { Bitset current = !bitsetList.isEmpty() ? bitsetList.get(bitsetList.size() - 1) : null; if (current == null || ttype > (current.shift + 63)) { current = new Bitset(); - current.shift = ttype; + if (useZeroOffset && ttype >= 0 && ttype < 63) { + current.shift = 0; + } + else { + current.shift = ttype; + } + bitsetList.add(current); }