mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
optimization
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@449 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
9b40c1fbdc
commit
26442ef453
7 changed files with 26 additions and 50 deletions
|
@ -21,8 +21,8 @@ public final class ZLIntArray {
|
|||
return myData[index];
|
||||
}
|
||||
|
||||
public void increment(int index) {
|
||||
++myData[index];
|
||||
public void incrementLast() {
|
||||
++myData[mySize - 1];
|
||||
}
|
||||
|
||||
public int size() {
|
||||
|
|
|
@ -40,6 +40,5 @@ public interface ZLTextParagraph {
|
|||
};
|
||||
|
||||
byte getKind();
|
||||
int getEntryNumber();
|
||||
int getTextLength();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
private final ArrayList<ZLImageEntry> myEntries = new ArrayList<ZLImageEntry>();
|
||||
private final ZLIntArray myStartEntryIndices = new ZLIntArray(1024);
|
||||
private final ZLIntArray myStartEntryOffsets = new ZLIntArray(1024);
|
||||
private final ZLIntArray myParagraphLengths = new ZLIntArray(1024);
|
||||
|
||||
private final ArrayList<char[]> myData = new ArrayList<char[]>(1024);
|
||||
private final int myDataBlockSize;
|
||||
|
@ -36,8 +37,8 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
|
||||
private ZLImageEntry myImageEntry;
|
||||
|
||||
EntryIteratorImpl(int index, int length) {
|
||||
myLength = length;
|
||||
EntryIteratorImpl(int index) {
|
||||
myLength = myParagraphLengths.get(index);
|
||||
myDataIndex = myStartEntryIndices.get(index);
|
||||
myDataOffset = myStartEntryOffsets.get(index);
|
||||
}
|
||||
|
@ -129,12 +130,11 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
myDataBlockSize = dataBlockSize;
|
||||
}
|
||||
|
||||
abstract void increaseLastParagraphSize();
|
||||
|
||||
void createParagraph() {
|
||||
final ArrayList<char[]> data = myData;
|
||||
myStartEntryIndices.add(data.isEmpty() ? 0 : (data.size() - 1));
|
||||
final int dataSize = myData.size();
|
||||
myStartEntryIndices.add((dataSize == 0) ? 0 : (dataSize - 1));
|
||||
myStartEntryOffsets.add(myBlockOffset);
|
||||
myParagraphLengths.add(0);
|
||||
}
|
||||
|
||||
private final char[] getDataBlock(int minimumLength) {
|
||||
|
@ -154,7 +154,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
|
||||
public final void addControl(byte textKind, boolean isStart) {
|
||||
final char[] block = getDataBlock(2);
|
||||
increaseLastParagraphSize();
|
||||
myParagraphLengths.incrementLast();
|
||||
block[myBlockOffset++] = (char)ZLTextParagraph.Entry.CONTROL;
|
||||
short kind = textKind;
|
||||
if (isStart) {
|
||||
|
@ -173,7 +173,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
|
||||
public final void addText(char[] text, int offset, int length) {
|
||||
char[] block = getDataBlock(3 + length);
|
||||
increaseLastParagraphSize();
|
||||
myParagraphLengths.incrementLast();
|
||||
int blockOffset = myBlockOffset;
|
||||
block[blockOffset++] = (char)ZLTextParagraph.Entry.TEXT;
|
||||
block[blockOffset++] = (char)(length >> 16);
|
||||
|
@ -185,7 +185,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
/*
|
||||
public final void addControl(ZLTextForcedControlEntry entry) {
|
||||
final char[] block = getDataBlock(3);
|
||||
increaseLastParagraphSize();
|
||||
myParagraphLengths.incrementLast();
|
||||
block[myBlockOffset++] = (char)ZLTextParagraph.Entry.FORCED_CONTROL;
|
||||
final int entryAddress = myEntries.size();
|
||||
block[myBlockOffset++] = (char)(entryAddress >> 16);
|
||||
|
@ -197,7 +197,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
public final void addHyperlinkControl(byte textKind, String label) {
|
||||
final short labelLength = (short)label.length();
|
||||
final char[] block = getDataBlock(3 + labelLength);
|
||||
increaseLastParagraphSize();
|
||||
myParagraphLengths.incrementLast();
|
||||
int blockOffset = myBlockOffset;
|
||||
block[blockOffset++] = (char)ZLTextParagraph.Entry.CONTROL;
|
||||
block[blockOffset++] = (char)(0x0300 + textKind);
|
||||
|
@ -210,7 +210,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
|
||||
public final void addImage(String id, ZLImageMap imageMap, short vOffset) {
|
||||
final char[] block = getDataBlock(2);
|
||||
increaseLastParagraphSize();
|
||||
myParagraphLengths.incrementLast();
|
||||
final ArrayList<ZLImageEntry> entries = myEntries;
|
||||
block[myBlockOffset++] = (char)ZLTextParagraph.Entry.IMAGE;
|
||||
block[myBlockOffset++] = (char)entries.size();
|
||||
|
@ -220,7 +220,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
/*
|
||||
public final void addFixedHSpace(short length) {
|
||||
final char[] block = getDataBlock(3);
|
||||
increaseLastParagraphSize();
|
||||
myParagraphLengths.incrementLast();
|
||||
block[myBlockOffset++] = (char)ZLTextParagraph.Entry.FIXED_HSPACE;
|
||||
final int entryAddress = myEntries.size();
|
||||
block[myBlockOffset++] = (char)(entryAddress >> 16);
|
||||
|
|
|
@ -5,32 +5,24 @@ import org.zlibrary.text.model.ZLTextParagraph;
|
|||
class ZLTextParagraphImpl implements ZLTextParagraph {
|
||||
private final ZLTextModelImpl myModel;
|
||||
private final int myIndex;
|
||||
private int myLength;
|
||||
|
||||
public int INDEX;
|
||||
|
||||
ZLTextParagraphImpl(ZLTextModelImpl model, int index, int length) {
|
||||
ZLTextParagraphImpl(ZLTextModelImpl model, int index) {
|
||||
myModel = model;
|
||||
myIndex = index;
|
||||
myLength = length;
|
||||
}
|
||||
|
||||
ZLTextParagraphImpl(ZLTextModelImpl model) {
|
||||
this(model, model.getParagraphsNumber(), 0);
|
||||
this(model, model.getParagraphsNumber());
|
||||
}
|
||||
|
||||
public EntryIterator iterator() {
|
||||
return myModel.new EntryIteratorImpl(myIndex, myLength);
|
||||
return myModel.new EntryIteratorImpl(myIndex);
|
||||
}
|
||||
|
||||
public byte getKind() {
|
||||
return Kind.TEXT_PARAGRAPH;
|
||||
}
|
||||
|
||||
public final int getEntryNumber() {
|
||||
return myLength;
|
||||
}
|
||||
|
||||
public final int getTextLength() {
|
||||
int size = 0;
|
||||
for (EntryIterator it = iterator(); it.hasNext(); ) {
|
||||
|
@ -40,8 +32,4 @@ class ZLTextParagraphImpl implements ZLTextParagraph {
|
|||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
final void addEntry() {
|
||||
++myLength;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,20 +17,14 @@ final class ZLTextPlainModelImpl extends ZLTextModelImpl implements ZLTextPlainM
|
|||
}
|
||||
|
||||
public final ZLTextParagraph getParagraph(int index) {
|
||||
final int info = myParagraphInfos.get(index);
|
||||
final byte kind = (byte)(info >> 24);
|
||||
final byte kind = (byte)myParagraphInfos.get(index);
|
||||
return (kind == ZLTextParagraph.Kind.TEXT_PARAGRAPH) ?
|
||||
new ZLTextParagraphImpl(this, index, info & 0x00FFFFFF) :
|
||||
new ZLTextSpecialParagraphImpl(kind, this, index, info & 0x00FFFFFF);
|
||||
new ZLTextParagraphImpl(this, index) :
|
||||
new ZLTextSpecialParagraphImpl(kind, this, index);
|
||||
}
|
||||
|
||||
void increaseLastParagraphSize() {
|
||||
final ZLIntArray infos = myParagraphInfos;
|
||||
infos.increment(infos.size() - 1);
|
||||
}
|
||||
|
||||
public void createParagraph(byte kind) {
|
||||
public final void createParagraph(byte kind) {
|
||||
createParagraph();
|
||||
myParagraphInfos.add(kind << 24);
|
||||
myParagraphInfos.add(kind);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ class ZLTextSpecialParagraphImpl extends ZLTextParagraphImpl {
|
|||
myKind = kind;
|
||||
}
|
||||
|
||||
ZLTextSpecialParagraphImpl(byte kind, ZLTextModelImpl model, int offset, int length) {
|
||||
super(model, offset, length);
|
||||
ZLTextSpecialParagraphImpl(byte kind, ZLTextModelImpl model, int offset) {
|
||||
super(model, offset);
|
||||
myKind = kind;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,12 +24,7 @@ public class ZLTextTreeModelImpl extends ZLTextModelImpl implements ZLTextTreeMo
|
|||
return myParagraphs.get(index);
|
||||
}
|
||||
|
||||
void increaseLastParagraphSize() {
|
||||
final ArrayList<ZLTextTreeParagraphImpl> paragraphs = myParagraphs;
|
||||
paragraphs.get(paragraphs.size() - 1).addEntry();
|
||||
}
|
||||
|
||||
public ZLTextTreeParagraph createParagraph(ZLTextTreeParagraph parent) {
|
||||
public final ZLTextTreeParagraph createParagraph(ZLTextTreeParagraph parent) {
|
||||
createParagraph();
|
||||
if (parent == null) {
|
||||
parent = myRoot;
|
||||
|
@ -39,7 +34,7 @@ public class ZLTextTreeModelImpl extends ZLTextModelImpl implements ZLTextTreeMo
|
|||
return tp;
|
||||
}
|
||||
|
||||
public void removeParagraph(int index) {
|
||||
public final void removeParagraph(int index) {
|
||||
ZLTextTreeParagraph p = getParagraph(index);
|
||||
p.removeFromParent();
|
||||
myParagraphs.remove(index);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue