You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by zi...@apache.org on 2004/01/27 02:30:17 UTC
cvs commit: xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal ByNameRuntimeBindingType.java ByNameTypeVisitor.java RuntimeBindingProperty.java RuntimeGlobalProperty.java
zieg 2004/01/26 17:30:17
Modified: v2/src/marshal/org/apache/xmlbeans/impl/marshal
ByNameRuntimeBindingType.java
ByNameTypeVisitor.java RuntimeBindingProperty.java
RuntimeGlobalProperty.java
Log:
use seperate arrays for elements and attributes for effeciency
Revision Changes Path
1.22 +60 -40 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java
Index: ByNameRuntimeBindingType.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ByNameRuntimeBindingType.java 26 Jan 2004 03:34:36 -0000 1.21
+++ ByNameRuntimeBindingType.java 27 Jan 2004 01:30:16 -0000 1.22
@@ -73,14 +73,16 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
+import java.util.Collection;
final class ByNameRuntimeBindingType
implements RuntimeBindingType
{
private final ByNameBean byNameBean;
- private final Property[] properties;
private final Class javaClass;
+ private final Property[] attributeProperties;
+ private final Property[] elementProperties;
private final boolean hasMulti; //has any multi properties
//is this a subtype of something besides the ultimate parent type?
@@ -101,8 +103,22 @@
throw new XmlRuntimeException(msg, e);
}
- properties = new Property[btype.getProperties().size()];
- hasMulti = hasMulti(btype);
+ int elem_prop_cnt = 0;
+ int att_prop_cnt = 0;
+ boolean has_multi = false;
+ final Collection type_props = btype.getProperties();
+ for (Iterator itr = type_props.iterator(); itr.hasNext();) {
+ QNameProperty p = (QNameProperty)itr.next();
+ if (p.isMultiple()) has_multi = true;
+ if (p.isAttribute())
+ att_prop_cnt++;
+ else
+ elem_prop_cnt++;
+ }
+
+ attributeProperties = new Property[att_prop_cnt];
+ elementProperties = new Property[elem_prop_cnt];
+ hasMulti = has_multi;
isSubType = determineIsSubType(javaClass);
}
@@ -117,25 +133,24 @@
return false;
}
- private static boolean hasMulti(ByNameBean btype)
- {
- for (Iterator itr = btype.getProperties().iterator(); itr.hasNext();) {
- QNameProperty bprop = (QNameProperty)itr.next();
- if (bprop.isMultiple())
- return true;
- }
- return false;
- }
-
//prepare internal data structures for use
public void initialize(RuntimeBindingTypeTable typeTable,
BindingLoader loader)
{
- int idx = 0;
+ int att_idx = 0;
+ int elem_idx = 0;
for (Iterator itr = byNameBean.getProperties().iterator(); itr.hasNext();) {
QNameProperty bprop = (QNameProperty)itr.next();
- Property prop = new Property(idx, javaClass, hasMulti, bprop, typeTable, loader);
- properties[idx++] = prop;
+ final boolean is_att = bprop.isAttribute();
+
+ final Property prop = new Property(is_att ? att_idx : elem_idx,
+ javaClass, hasMulti, bprop,
+ typeTable, loader);
+ if (is_att)
+ attributeProperties[att_idx++] = prop;
+ else
+ elementProperties[elem_idx++] = prop;
+
}
}
@@ -168,18 +183,22 @@
}
- RuntimeBindingProperty getProperty(int index)
+ RuntimeBindingProperty getElementProperty(int index)
{
- return properties[index];
+ return elementProperties[index];
+ }
+
+ RuntimeBindingProperty getAttributeProperty(int index)
+ {
+ return attributeProperties[index];
}
//TODO: optimize this linear scan
RuntimeBindingProperty getMatchingElementProperty(String uri,
String localname)
{
- for (int i = 0, len = properties.length; i < len; i++) {
- final Property prop = properties[i];
- if (prop.isAttribute()) continue;
+ for (int i = 0, len = elementProperties.length; i < len; i++) {
+ final Property prop = elementProperties[i];
if (doesPropMatch(uri, localname, prop))
return prop;
@@ -191,9 +210,8 @@
RuntimeBindingProperty getMatchingAttributeProperty(String uri,
String localname)
{
- for (int i = 0, len = properties.length; i < len; i++) {
- final Property prop = properties[i];
- if (!prop.isAttribute()) continue;
+ for (int i = 0, len = attributeProperties.length; i < len; i++) {
+ final Property prop = attributeProperties[i];
if (doesPropMatch(uri, localname, prop))
return prop;
@@ -205,6 +223,8 @@
String localname,
Property prop)
{
+ assert localname != null;
+
final QName qn = prop.getQName();
if (qn.getLocalPart().equals(localname)) {
@@ -215,9 +235,14 @@
return false;
}
- public int getPropertyCount()
+ public int getElementPropertyCount()
{
- return properties.length;
+ return elementProperties.length;
+ }
+
+ public int getAttributePropertyCount()
+ {
+ return attributeProperties.length;
}
public boolean isSubType()
@@ -555,11 +580,6 @@
}
- public boolean isAttribute()
- {
- return bindingProperty.isAttribute();
- }
-
QName getQName()
{
return bindingProperty.getQName();
@@ -584,7 +604,7 @@
Object getFinalValue()
{
if (accumulators != null) {
- final Property[] props = runtimeBindingType.properties;
+ final Property[] props = runtimeBindingType.elementProperties;
for (int i = 0, len = accumulators.length; i < len; i++) {
final Accumulator accum = accumulators[i];
if (accum != null) {
@@ -596,22 +616,22 @@
return value;
}
- void addItem(int property_index, Object value)
+ void addItem(int elem_idx, Object value)
{
- initAccumulator(property_index);
- accumulators[property_index].append(value);
+ initAccumulator(elem_idx);
+ accumulators[elem_idx].append(value);
}
- private void initAccumulator(int property_index)
+ private void initAccumulator(int elem_idx)
{
Accumulator[] accs = accumulators;
if (accs == null) {
- accs = new Accumulator[runtimeBindingType.getPropertyCount()];
+ accs = new Accumulator[runtimeBindingType.getElementPropertyCount()];
accumulators = accs;
}
- if (accs[property_index] == null) {
- final Property p = runtimeBindingType.properties[property_index];
- accs[property_index] =
+ if (accs[elem_idx] == null) {
+ final Property p = runtimeBindingType.elementProperties[elem_idx];
+ accs[elem_idx] =
AccumulatorFactory.createAccumulator(p.propertyClass,
p.collectionElementClass);
}
1.13 +21 -22 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameTypeVisitor.java
Index: ByNameTypeVisitor.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameTypeVisitor.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ByNameTypeVisitor.java 22 Jan 2004 21:43:47 -0000 1.12
+++ ByNameTypeVisitor.java 27 Jan 2004 01:30:16 -0000 1.13
@@ -68,8 +68,9 @@
final class ByNameTypeVisitor extends NamedXmlTypeVisitor
{
private final ByNameRuntimeBindingType type;
- private final int maxPropCount;
- private int propIdx = -1;
+ private final int maxElementPropCount;
+ private final int maxAttributePropCount;
+ private int elemPropIdx = -1;
private List attributeNames;
private List attributeValues;
private Iterator currMultipleIterator;
@@ -84,30 +85,31 @@
final BindingType pt = property.getType();
type = (ByNameRuntimeBindingType)result.createRuntimeBindingType(pt, obj);
- maxPropCount = obj == null ? 0 : type.getPropertyCount();
+ maxElementPropCount = obj == null ? 0 : type.getElementPropertyCount();
+ maxAttributePropCount = obj == null ? 0 : type.getAttributePropertyCount();
}
protected int getState()
{
- assert propIdx <= maxPropCount; //ensure we don't go past the end
+ assert elemPropIdx <= maxElementPropCount; //ensure we don't go past the end
- if (propIdx < 0) return START;
+ if (elemPropIdx < 0) return START;
- if (propIdx >= maxPropCount) return END;
+ if (elemPropIdx >= maxElementPropCount) return END;
return CONTENT;
}
protected int advance()
{
- assert propIdx < maxPropCount; //ensure we don't go past the end
+ assert elemPropIdx < maxElementPropCount; //ensure we don't go past the end
do {
boolean hit_end = advanceToNextItem();
if (hit_end) return END;
} while (!currentPropHasMore());
- assert propIdx >= 0;
+ assert elemPropIdx >= 0;
return getState();
}
@@ -126,11 +128,11 @@
//return true if we hit the end of our properties
private boolean advanceToNextProperty()
{
- propIdx++;
+ elemPropIdx++;
currMultipleIterator = null;
haveMultipleItem = false;
- if (propIdx >= maxPropCount) return true;
+ if (elemPropIdx >= maxElementPropCount) return true;
updateCurrIterator();
@@ -139,7 +141,7 @@
private void updateCurrIterator()
{
- final RuntimeBindingProperty property = getCurrentProperty();
+ final RuntimeBindingProperty property = getCurrentElementProperty();
if (property.isMultiple()) {
Object prop_obj = property.getValue(getParentObject(), marshalResult);
final Iterator itr = MarshalResult.getCollectionIterator(prop_obj);
@@ -155,18 +157,16 @@
private boolean currentPropHasMore()
{
- if (propIdx < 0) return false;
+ if (elemPropIdx < 0) return false;
if (haveMultipleItem) {
if (currMultipleItem != null) return true;
//skip null items in a collection if this element is not nillable
- return (getCurrentProperty().isNillable());
+ return (getCurrentElementProperty().isNillable());
}
if (currMultipleIterator != null) return false; //an empty collection
- final RuntimeBindingProperty property = getCurrentProperty();
-
- if (property.isAttribute()) return false;
+ final RuntimeBindingProperty property = getCurrentElementProperty();
final boolean set = property.isSet(getParentObject(), marshalResult);
return set;
@@ -174,7 +174,7 @@
public XmlTypeVisitor getCurrentChild()
{
- final RuntimeBindingProperty property = getCurrentProperty();
+ final RuntimeBindingProperty property = getCurrentElementProperty();
if (haveMultipleItem) {
return MarshalResult.createVisitor(property, currMultipleItem,
@@ -188,9 +188,9 @@
}
}
- private RuntimeBindingProperty getCurrentProperty()
+ private RuntimeBindingProperty getCurrentElementProperty()
{
- final RuntimeBindingProperty property = type.getProperty(propIdx);
+ final RuntimeBindingProperty property = type.getElementProperty(elemPropIdx);
assert property != null;
return property;
}
@@ -230,10 +230,9 @@
vals.add(aval);
}
- for (int i = 0, len = maxPropCount; i < len; i++) {
- final RuntimeBindingProperty prop = type.getProperty(i);
+ for (int i = 0, len = maxAttributePropCount; i < len; i++) {
+ final RuntimeBindingProperty prop = type.getAttributeProperty(i);
- if (!prop.isAttribute()) continue;
if (!prop.isSet(getParentObject(), marshalResult)) continue;
final Object value = prop.getValue(getParentObject(),
1.10 +0 -2 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingProperty.java
Index: RuntimeBindingProperty.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingProperty.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- RuntimeBindingProperty.java 22 Jan 2004 21:43:47 -0000 1.9
+++ RuntimeBindingProperty.java 27 Jan 2004 01:30:16 -0000 1.10
@@ -67,8 +67,6 @@
QName getName();
- boolean isAttribute();
-
TypeUnmarshaller getTypeUnmarshaller(UnmarshalResult context);
void fill(Object inter, Object prop_obj);
1.9 +0 -5 xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeGlobalProperty.java
Index: RuntimeGlobalProperty.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeGlobalProperty.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- RuntimeGlobalProperty.java 22 Jan 2004 21:43:47 -0000 1.8
+++ RuntimeGlobalProperty.java 27 Jan 2004 01:30:16 -0000 1.9
@@ -84,11 +84,6 @@
return rootElement;
}
- public boolean isAttribute()
- {
- return false;
- }
-
public TypeUnmarshaller getTypeUnmarshaller(UnmarshalResult context)
{
throw new UnsupportedOperationException();
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org