Use a zero offset for the first bitset as long as it doesn't force the creation of additional sets

This commit is contained in:
Sam Harwell 2012-11-27 08:46:16 -06:00
parent ad242a0c7a
commit 11385f7920
1 changed files with 11 additions and 3 deletions

View File

@ -44,17 +44,25 @@ public class TestSetInline extends SrcOp {
public TestSetInline(OutputModelFactory factory, GrammarAST ast, IntervalSet set) { public TestSetInline(OutputModelFactory factory, GrammarAST ast, IntervalSet set) {
super(factory, ast); 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"; this.varName = "_la";
} }
private static Bitset[] createBitsets(OutputModelFactory factory, IntervalSet set) { private static Bitset[] createBitsets(OutputModelFactory factory, IntervalSet set, boolean useZeroOffset) {
List<Bitset> bitsetList = new ArrayList<Bitset>(); List<Bitset> bitsetList = new ArrayList<Bitset>();
for (int ttype : set.toArray()) { for (int ttype : set.toArray()) {
Bitset current = !bitsetList.isEmpty() ? bitsetList.get(bitsetList.size() - 1) : null; Bitset current = !bitsetList.isEmpty() ? bitsetList.get(bitsetList.size() - 1) : null;
if (current == null || ttype > (current.shift + 63)) { if (current == null || ttype > (current.shift + 63)) {
current = new Bitset(); current = new Bitset();
if (useZeroOffset && ttype >= 0 && ttype < 63) {
current.shift = 0;
}
else {
current.shift = ttype; current.shift = ttype;
}
bitsetList.add(current); bitsetList.add(current);
} }