Author: adelmelle
Date: Sat Jan 22 18:28:57 2011
New Revision: 1062225
URL: http://svn.apache.org/viewvc?rev=1062225&view=rev
Log:
Bugzilla 50626: Fix potential performance issue when adding nodes. Thanks to
mkoegler.AT.auto.tuwien.ac.at.
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java?rev=1062225&r1=1062224&r2=1062225&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java Sat Jan 22
18:28:57 2011
@@ -51,12 +51,13 @@ public abstract class FObj extends FONod
* pointer to the descendant subtree
*/
protected FONode firstChild;
+ protected FONode lastChild;
/** The list of extension attachments, null if none */
- private List/*<ExtensionAttachment>*/ extensionAttachments = null;
+ private List<ExtensionAttachment> extensionAttachments = null;
/** The map of foreign attributes, null if none */
- private Map/*<QName,String>*/ foreignAttributes = null;
+ private Map<QName, String> foreignAttributes = null;
/** Used to indicate if this FO is either an Out Of Line FO (see rec)
* or a descendant of one. Used during FO validation.
@@ -197,13 +198,19 @@ public abstract class FObj extends FONod
} else {
if (firstChild == null) {
firstChild = child;
+ lastChild = child;
} else {
- FONode prevChild = firstChild;
- while (prevChild.siblings != null
- && prevChild.siblings[1] != null) {
- prevChild = prevChild.siblings[1];
+ if (lastChild == null) {
+ FONode prevChild = firstChild;
+ while (prevChild.siblings != null
+ && prevChild.siblings[1] != null) {
+ prevChild = prevChild.siblings[1];
+ }
+ FONode.attachSiblings(prevChild, child);
+ } else {
+ FONode.attachSiblings(lastChild, child);
+ lastChild = child;
}
- FONode.attachSiblings(prevChild, child);
}
}
}
@@ -238,6 +245,13 @@ public abstract class FObj extends FONod
nextChild.siblings[0] = prevChild;
}
}
+ if (child == lastChild) {
+ if (child.siblings != null) {
+ lastChild = siblings[0];
+ } else {
+ lastChild = null;
+ }
+ }
}
/**
@@ -421,6 +435,7 @@ public abstract class FObj extends FONod
* Convenience method for validity checking. Checks if the
* incoming node is a member of the "%block;" parameter entity
* as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+ *
* @param nsURI namespace URI of incoming node
* @param lName local name (i.e., no prefix) of incoming node
* @return true if a member, false if not
@@ -440,6 +455,7 @@ public abstract class FObj extends FONod
* Convenience method for validity checking. Checks if the
* incoming node is a member of the "%inline;" parameter entity
* as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+ *
* @param nsURI namespace URI of incoming node
* @param lName local name (i.e., no prefix) of incoming node
* @return true if a member, false if not
@@ -529,7 +545,7 @@ public abstract class FObj extends FONod
/** @return whether this object has an id set */
public boolean hasId() {
- return id != null && id.length() > 0;
+ return (id != null && id.length() > 0);
}
/** {@inheritDoc} */
@@ -554,7 +570,7 @@ public abstract class FObj extends FONod
"Parameter attachment must not be null");
}
if (extensionAttachments == null) {
- extensionAttachments = new
java.util.ArrayList/*<ExtensionAttachment>*/();
+ extensionAttachments = new
java.util.ArrayList<ExtensionAttachment>();
}
if (log.isDebugEnabled()) {
log.debug("ExtensionAttachment of category "
@@ -591,7 +607,7 @@ public abstract class FObj extends FONod
throw new NullPointerException("Parameter attributeName must not
be null");
}
if (foreignAttributes == null) {
- foreignAttributes = new java.util.HashMap/*<QName,String>*/();
+ foreignAttributes = new java.util.HashMap<QName, String>();
}
foreignAttributes.put(attributeName, value);
}
@@ -679,6 +695,9 @@ public abstract class FObj extends FONod
&& currentNode.siblings[1] != null) {
FONode.attachSiblings(newNode, currentNode.siblings[1]);
}
+ if (currentNode == parentNode.lastChild) {
+ parentNode.lastChild = newNode;
+ }
} else {
throw new IllegalStateException();
}
@@ -694,12 +713,18 @@ public abstract class FObj extends FONod
parentNode.firstChild = newNode;
currentIndex = 0;
currentNode = newNode;
+ if (parentNode.lastChild == null) {
+ parentNode.lastChild = newNode;
+ }
} else {
if (currentNode.siblings != null
&& currentNode.siblings[1] != null) {
FONode.attachSiblings((FONode) o, currentNode.siblings[1]);
}
FONode.attachSiblings(currentNode, (FONode) o);
+ if (currentNode == parentNode.lastChild) {
+ parentNode.lastChild = newNode;
+ }
}
flags &= F_NONE_ALLOWED;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]