Author: julien(a)jboss.com
Date: 2007-06-26 21:39:01 -0400 (Tue, 26 Jun 2007)
New Revision: 7574
Modified:
tags/JBoss_Portal_2_6_0/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
Log:
port children access optimization to GA as it matters to have efficency
Modified:
tags/JBoss_Portal_2_6_0/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
---
tags/JBoss_Portal_2_6_0/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-06-27
01:31:54 UTC (rev 7573)
+++
tags/JBoss_Portal_2_6_0/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-06-27
01:39:01 UTC (rev 7574)
@@ -36,6 +36,8 @@
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.HashSet;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -69,7 +71,7 @@
private Map childrenMap;
private Map properties;
private Map unmodifiableProperties;
- private boolean childrenAccessed;
+ private Set accessedChildren;
public PortalObjectImpl()
{
@@ -85,7 +87,7 @@
this.childrenMap = null;
this.properties = null;
this.unmodifiableProperties = null;
- this.childrenAccessed = false;
+ this.accessedChildren = null;
}
public Long getKey()
@@ -231,10 +233,20 @@
public Object[] toArray(Object a[])
{
ArrayList tmp = new ArrayList(objectNode.getChildren().size());
+
+ //
+ Set accessedChildren = getAccessedChildren();
+
+ //
for (Iterator i = iterator(); i.hasNext();)
{
- PortalObject child = (PortalObject)i.next();
- tmp.add(child);
+ PortalObject childObject = (PortalObject)i.next();
+
+ //
+ accessedChildren.add(childObject);
+
+ //
+ tmp.add(childObject);
}
return tmp.toArray(a);
}
@@ -246,9 +258,8 @@
private final Iterator iterator;
/** . */
- private PortalObject next = null;
+ private PortalObject nextChild = null;
-
public ChildrenIterator()
{
Map childrenMap = objectNode.getChildren();
@@ -263,34 +274,41 @@
public boolean hasNext()
{
- if (next == null)
+ if (nextChild == null)
{
- while (next == null && iterator.hasNext())
+ while (nextChild == null && iterator.hasNext())
{
- ObjectNode node = (ObjectNode)iterator.next();
- PortalObjectImpl object = node.getObject();
- if (mask == ALL_TYPES_MASK || (object.getMask() & mask) != 0)
+ ObjectNode childNode = (ObjectNode)iterator.next();
+ PortalObjectImpl childObject = childNode.getObject();
+ if (mask == ALL_TYPES_MASK || (childObject.getMask() & mask) !=
0)
{
- next = object;
+ nextChild = childObject;
}
}
}
- return next != null;
+ return nextChild != null;
}
public Object next()
{
- if (next == null)
+ if (this.nextChild == null)
{
hasNext();
}
- if (next == null)
+ if (this.nextChild == null)
{
throw new NoSuchElementException();
}
- PortalObject next = this.next;
- this.next = null;
- return next;
+
+ //
+ getAccessedChildren().add(nextChild);
+
+ //
+ PortalObject nextChild = this.nextChild;
+ this.nextChild = null;
+
+ //
+ return nextChild;
}
}
}
@@ -308,7 +326,6 @@
if (childrenMap == null)
{
childrenMap = new HashMap();
- childrenAccessed = true;
}
else
{
@@ -355,8 +372,13 @@
ObjectNode childNode = (ObjectNode)objectNode.getChildren().get(name);
if (childNode != null)
{
- childrenAccessed = true;
- return childNode.getObject();
+ PortalObjectImpl childObject = childNode.getObject();
+
+ // Track it
+ getAccessedChildren().add(childObject);
+
+ //
+ return childObject;
}
else
{
@@ -364,6 +386,15 @@
}
}
+ private Set getAccessedChildren()
+ {
+ if (accessedChildren == null)
+ {
+ accessedChildren = new HashSet();
+ }
+ return accessedChildren;
+ }
+
/**
* Get the aggregated properties in a lazy manner.
*/
@@ -465,12 +496,12 @@
}
//
- if (childrenAccessed)
+ if (accessedChildren != null)
{
- for (Iterator i = this.getChildren().iterator();i.hasNext();)
+ for (Iterator i = accessedChildren.iterator(); i.hasNext();)
{
- PortalObjectImpl child = (PortalObjectImpl)i.next();
- child.propagatePropertyUpdate(name, value, false);
+ PortalObjectImpl child = (PortalObjectImpl)i.next();
+ child.propagatePropertyUpdate(name, value, false);
}
}
}
@@ -592,7 +623,9 @@
protected final void addChild(String name, PortalObjectImpl childObject) throws
DuplicatePortalObjectException, IllegalArgumentException
{
objectNode.addChild(name, childObject);
- childrenAccessed = true;
+
+ //
+ getAccessedChildren().add(childObject);
}
private PortalObjectImpl copy(PortalObjectImpl parent, String name, boolean deep)
throws DuplicatePortalObjectException
Show replies by date