Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory usage and improve performance. #409

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected JRFillElement(

printElementOriginator = filler.assignElementId(this);

/* */
/* */
printWhenGroupChanges = factory.getGroup(element.getPrintWhenGroupChanges());
elementGroup = (JRFillElementGroup)factory.getVisitResult(element.getElementGroup());

Expand Down Expand Up @@ -232,7 +232,7 @@ protected JRFillElement(JRFillElement element, JRFillCloneFactory factory)

printElementOriginator = element.printElementOriginator;

/* */
/* */
printWhenGroupChanges = element.printWhenGroupChanges;
elementGroup = (JRFillElementGroup) factory.getClone((JRFillElementGroup) element.getElementGroup());

Expand Down Expand Up @@ -681,7 +681,7 @@ protected void setCollapsedHeightAbove(int collapsedHeightAbove)
this.collapsedHeightAbove = collapsedHeightAbove;
}

/**
/**
*
*/
protected int getCollapsedHeightBelow()
Expand Down Expand Up @@ -839,7 +839,7 @@ protected void evaluateStyle(
{
throw
new JRRuntimeException(
JRFillObjectFactory.EXCEPTION_MESSAGE_KEY_STYLE_NOT_FOUND,
JRFillObjectFactory.EXCEPTION_MESSAGE_KEY_STYLE_NOT_FOUND,
new Object[]{styleName}
);
}
Expand Down Expand Up @@ -989,7 +989,7 @@ protected boolean prepare(
if (
isPrintWhenExpressionNull() ||
( !isPrintWhenExpressionNull() &&
isPrintWhenTrue() )
isPrintWhenTrue() )
)
{
setToPrint(true);
Expand Down Expand Up @@ -1185,23 +1185,14 @@ protected void _moveDependantElements()
/**
*
*/
protected void moveDependantElements()
{
protected void moveDependantElements() {
Collection<JRFillElement> elements = getDependantElements();
if (elements != null && elements.size() > 0)
{
for (JRFillElement element : elements)
{
int newRelativeY =
getRelativeY() + getStretchHeight() //pusher element current bottom edge
+ (element.getY() - (getY() + getHeight())) //design time distance between elements; difference between float element top edge and pusher element bottom edge
- (element.getCollapsedHeightAbove() - getCollapsedHeightAbove()); //difference in collapsedY amount, meaning the elements could only have become closer together due to blank element removal

if (newRelativeY > element.getRelativeY())
{
if (elements != null && !elements.isEmpty()) {
int offset = getRelativeY() + getStretchHeight() - getY() - getHeight() + getCollapsedHeightAbove();
for (JRFillElement element : elements) {
int newRelativeY = offset + element.getY() - element.getCollapsedHeightAbove();
if (newRelativeY > element.getRelativeY()) {
element.setRelativeY(newRelativeY);

element.moveDependantElements();
}
}
}
Expand Down Expand Up @@ -1297,7 +1288,7 @@ public final Object evaluateExpression(JRExpression expression, byte evaluation)
* Decides whether the value for this element is repeating.
* <p>
* Dynamic elements should call {@link #setValueRepeating(boolean) setValueRepeating(boolean)} on
* {@link #evaluate(byte) evaluate(byte)}. Static elements don't have to do anything, this method
* {@link #evaluate(byte) evaluate(byte)}. Static elements don't have to do anything, this method
* will return <code>true</code> by default.
*
* @return whether the value for this element is repeating
Expand Down Expand Up @@ -2006,7 +1997,7 @@ public static Integer getBookmarkLevel(Object value) throws JRException
{
throw
new JRException(
EXCEPTION_MESSAGE_KEY_INVALID_BOOKMARK_LEVEL,
EXCEPTION_MESSAGE_KEY_INVALID_BOOKMARK_LEVEL,
new Object[] {value}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,25 @@ protected final void _initElements()
}
}

/* */
/* */
Collections.sort(sortedElemsList, new JRYComparator());
ySortedElements = new JRFillElement[elements.length];
sortedElemsList.toArray(ySortedElements);

/* */
/* */
stretchElements = new JRFillElement[stretchElemsList.size()];
stretchElemsList.toArray(stretchElements);

/* */
/* */
bandBottomElements = new JRFillElement[bandBottomElemsList.size()];
bandBottomElemsList.toArray(bandBottomElements);

/* */
/* */
removableElements = new JRFillElement[removableElemsList.size()];
removableElemsList.toArray(removableElements);
}

/* */
/* */
setDependentElements();
}

Expand All @@ -251,7 +251,7 @@ protected final void initElements()

JRYComparator yComparator = new JRYComparator();

/* */
/* */
ySortedElements = Arrays.copyOf(elements, elements.length);
Arrays.sort(ySortedElements, yComparator);

Expand Down Expand Up @@ -301,60 +301,52 @@ protected final void initElements()
}
}

/* */
/* */
stretchElements = new JRFillElement[stretchElemsList.size()];
stretchElemsList.toArray(stretchElements);

/* */
/* */
bandBottomElements = new JRFillElement[bandBottomElemsList.size()];
bandBottomElemsList.toArray(bandBottomElements);

/* */
/* */
removableElements = new JRFillElement[removableElemsList.size()];
removableElemsList.toArray(removableElements);
}

/* */
/* */
setDependentElements();
}

/**
*
*/
private void setDependentElements()
{
if (ySortedElements != null && ySortedElements.length > 0)
{
for(int i = 0; i < ySortedElements.length - 1; i++)
{
private void setDependentElements() {
if (ySortedElements != null && ySortedElements.length > 0) {
outerLoop:
for (int i = 0; i < ySortedElements.length - 1; i++) {
JRFillElement iElem = ySortedElements[i];
boolean isBreakElem = iElem instanceof JRFillBreak;

for(int j = i + 1; j < ySortedElements.length; j++)
{
int iElemX = iElem.getX();
int iElemWidth = iElem.getWidth();
int iElemRight = iElemX + iElemWidth;
int iElemBottom = iElem.getY() + iElem.getHeight();
for (int j = i + 1; j < ySortedElements.length; j++) {
JRFillElement jElem = ySortedElements[j];

int left = Math.min(iElem.getX(), jElem.getX());
int right = Math.max(iElem.getX() + iElem.getWidth(), jElem.getX() + jElem.getWidth());

if (
((isBreakElem && jElem.getPositionTypeValue() == PositionTypeEnum.FIX_RELATIVE_TO_TOP) || jElem.getPositionTypeValue() == PositionTypeEnum.FLOAT) &&
iElem.getY() + iElem.getHeight() <= jElem.getY() &&
iElem.getWidth() + jElem.getWidth() > right - left // FIXME band bottom elements should not have dependent elements
)
{
int jElemX = jElem.getX();
int jElemWidth = jElem.getWidth();
int jElemRight = jElemX + jElemWidth;
PositionTypeEnum positionType = jElem.getPositionTypeValue();
if (((isBreakElem && positionType == PositionTypeEnum.FIX_RELATIVE_TO_TOP)
|| positionType == PositionTypeEnum.FLOAT)
&& iElemBottom <= jElem.getY()
&& iElemWidth + jElemWidth > Math.max(iElemRight, jElemRight) - Math.min(iElemX, jElemX)) {
iElem.addDependantElement(jElem);
if (jElemX <= iElemX && jElemRight >= iElemRight) {
continue outerLoop;
}
}
}

/*
if (iElem.getParent().getElementGroup() != null) //parent might be null
{
iElem.setGroupElements(
iElem.getParent().getElementGroup().getElements()
);
}
*/
}
}
}
Expand Down Expand Up @@ -538,6 +530,9 @@ protected void prepareElements(
{
for (JRFillElement element : ySortedElements)
{
if (currentOverflowWithElements && isOverflowAllowed && element.getY() > firstY + availableHeight) {
break;
}
currentOverflowWithElements =
element.prepare(
availableHeight + getElementFirstY(element),
Expand Down