Skip to content

Commit

Permalink
Improves splitting performance in SheetDataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Håkansson committed Nov 30, 2017
1 parent 1787003 commit cdb0b51
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/org/daisy/dotify/formatter/impl/sheet/SheetDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public class SheetDataSource implements SplitPointDataSource<Sheet> {
private int initialPageOffset;
private boolean volBreakAllowed;
private boolean updateCounter;
private boolean allowsSplit;
//Output buffer
private List<Sheet> sheetBuffer;


public SheetDataSource(PageStruct struct, FormatterContext context, DefaultContext rcontext, Integer volumeGroup, List<BlockSequence> seqsIterator) {
this.struct = struct;
this.context = context;
Expand All @@ -65,6 +65,7 @@ public SheetDataSource(PageStruct struct, FormatterContext context, DefaultConte
this.counter = null;
this.initialPageOffset = 0;
this.updateCounter = false;
this.allowsSplit = true;
}

public SheetDataSource(SheetDataSource template) {
Expand All @@ -87,7 +88,7 @@ private SheetDataSource(SheetDataSource template, int offset, boolean tail) {
this.volumeGroup = template.volumeGroup;
this.seqsIterator = template.seqsIterator;
this.seqsIndex = template.seqsIndex;
this.psb = PageSequenceBuilder2.copyUnlessNull(template.psb);
this.psb = tail?template.psb:PageSequenceBuilder2.copyUnlessNull(template.psb);
this.sectionProperties = template.sectionProperties;
this.sheetOffset = template.sheetOffset+offset;
this.sheetIndex = template.sheetIndex;
Expand All @@ -100,7 +101,8 @@ private SheetDataSource(SheetDataSource template, int offset, boolean tail) {
this.volBreakAllowed = template.volBreakAllowed;
this.counter = template.counter;
this.initialPageOffset = template.initialPageOffset;
this.updateCounter = template.updateCounter;
this.updateCounter = tail?true:template.updateCounter;
this.allowsSplit = true;
}

@Override
Expand Down Expand Up @@ -263,6 +265,10 @@ private void setPreviousSheet(int start, int p, DefaultContext rcontext) {

@Override
public SplitResult<Sheet> split(int atIndex) {
if (!allowsSplit) {
throw new IllegalStateException();
}
allowsSplit = false;
if (!ensureBuffer(atIndex)) {
throw new IndexOutOfBoundsException("" + atIndex);
}
Expand All @@ -271,12 +277,10 @@ public SplitResult<Sheet> split(int atIndex) {
} else {
struct.setDefaultPageOffset(initialPageOffset + psb.getSizeLast());
}
SheetDataSource tail = new SheetDataSource(this, atIndex, true);
tail.updateCounter = true;
if (atIndex==0) {
return new SplitResult<Sheet>(Collections.emptyList(), tail);
return new SplitResult<Sheet>(Collections.emptyList(), new SheetDataSource(this, atIndex, true));
} else {
return new SplitResult<Sheet>(sheetBuffer.subList(0, atIndex), tail);
return new SplitResult<Sheet>(sheetBuffer.subList(0, atIndex), new SheetDataSource(this, atIndex, true));
}
}

Expand Down

0 comments on commit cdb0b51

Please sign in to comment.