You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2005/03/18 19:20:10 UTC
svn commit: r158116 - in
xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store: DomImpl.java
Locale.java Xobj.java
Author: cezar
Date: Fri Mar 18 10:20:08 2005
New Revision: 158116
URL: http://svn.apache.org/viewcvs?view=rev&rev=158116
Log:
Contributed by:Yana Kadiyska. DOM perf chages
Modified:
xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/DomImpl.java
xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java
xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Xobj.java
Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/DomImpl.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/DomImpl.java?view=diff&r1=158115&r2=158116
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/DomImpl.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/DomImpl.java Fri Mar 18 10:20:08 2005
@@ -1308,6 +1308,13 @@
case DOCFRAG :
case ATTR :
{
+ if (n instanceof Xobj)
+ {
+ Xobj node = (Xobj) n;
+ if (node.isFirstChildPtrDomUsable())
+ return (Xobj.NodeXobj) node._firstChild;
+ }
+
Cur c = n.tempCur();
c.next();
@@ -1462,6 +1469,13 @@
case COMMENT :
case ELEMENT :
{
+ if (n instanceof Xobj)
+ {
+ Xobj node = (Xobj) n;
+ if (node.isNextSiblingPtrDomUsable())
+ return
+ (Xobj.NodeXobj) node._nextSibling;
+ }
Cur c = n.tempCur();
c.skip();
@@ -2535,7 +2549,14 @@
//
//return null;
- // TODO - optimize for the 0 and 1 child case
+ // optimize for the 0 and 1 child case
+ if (i == 0 && (n instanceof Xobj))
+ {
+ Xobj node = (Xobj) n;
+ if (node.isFirstChildPtrDomUsable())
+ return
+ (Xobj.NodeXobj) node._firstChild;
+ }
return n.locale().findDomNthChild(n, i);
}
@@ -2591,7 +2612,15 @@
//return len;
- // TODO - optimize for the 0 and 1 child case
+ //optimize for the 0 and 1 child case
+
+ if (n instanceof Xobj)
+ {
+ Xobj node = (Xobj) n;
+ int count;
+ if ((count = node.getDomZeroOneChildren()) < 2)
+ return count;
+ }
return n.locale().domLength(n);
}
Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java?view=diff&r1=158115&r2=158116
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java Fri Mar 18 10:20:08 2005
@@ -2392,14 +2392,32 @@
if (parent == null)
return null;
- int da = _domNthCache_A.distance( parent, n );
- int db = _domNthCache_B.distance( parent, n );
-
- Dom x =
- da <= db
- ? _domNthCache_A.fetch( parent, n )
- : _domNthCache_B.fetch( parent, n );
+ int da = _domNthCache_A.distance(parent, n);
+ int db = _domNthCache_B.distance(parent, n);
+
+ // the "better" cache should never walk more than 1/2 len
+ Dom x = null;
+ boolean bInvalidate = (db - _domNthCache_B._len / 2 > 0) &&
+ (db - _domNthCache_B._len / 2 - domNthCache.BLITZ_BOUNDARY > 0);
+ boolean aInvalidate = (da - _domNthCache_A._len / 2 > 0) &&
+ (da - _domNthCache_A._len / 2 - domNthCache.BLITZ_BOUNDARY > 0);
+ if (da <= db)
+ if (!aInvalidate)
+ x = _domNthCache_A.fetch(parent, n);
+ else
+ {
+ _domNthCache_B._version = -1;//blitz the cache
+ x = _domNthCache_B.fetch(parent, n);
+ }
+ else if (!bInvalidate)
+ x = _domNthCache_B.fetch(parent, n);
+ else
+ {
+ _domNthCache_A._version = -1;//blitz the cache
+ x = _domNthCache_A.fetch(parent, n);
+ }
+
if (da == db)
{
domNthCache temp = _domNthCache_A;
@@ -2566,7 +2584,8 @@
return _child;
}
- private long _version;
+ public static final int BLITZ_BOUNDARY = 40; //walk small lists
+ private long _version;
private Dom _parent;
private Dom _child;
private int _n;
Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Xobj.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Xobj.java?view=diff&r1=158115&r2=158116
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Xobj.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Xobj.java Fri Mar 18 10:20:08 2005
@@ -158,6 +158,90 @@
final boolean hasAttrs ( ) { return _firstChild != null && _firstChild.isAttr(); }
final boolean hasChildren ( ) { return _lastChild != null && !_lastChild .isAttr(); }
+
+ /**
+ * this method is to speed up DomImpl
+ * when underlying obj is an Xobj
+ *
+ * @return 0 or 1 dom children; val 2 indicates that DomImpl needs to
+ * compute the result itself
+ */
+ final protected int getDomZeroOneChildren()
+ {
+ if (_firstChild == null &&
+ _srcValue == null &&
+ _charNodesValue == null)
+ return 0;
+
+ if (_lastChild != null &&
+ _lastChild.isAttr() &&
+ _lastChild._charNodesAfter == null &&
+ _lastChild._srcAfter == null &&
+ _srcValue == null &&
+ _charNodesValue == null
+ )
+ return 0;
+
+ if (_firstChild == _lastChild &&
+ _firstChild != null &&
+ !_firstChild.isAttr() &&
+ _srcValue == null &&
+ _charNodesValue == null &&
+ _firstChild._srcAfter == null
+ )
+ return 1;
+
+ if (_firstChild == null &&
+ _srcValue != null &&
+ _charNodesValue == null)
+ return 1;
+ return 2;
+ }
+
+ /**
+ * can one use the _firstChild pointer to retrieve
+ * the first DOM child
+ *
+ * @return
+ */
+ final protected boolean isFirstChildPtrDomUsable()
+ {
+ if (_firstChild == null &&
+ _srcValue == null &&
+ _charNodesValue == null)
+ return true;
+
+ if (_firstChild != null &&
+ !_firstChild.isAttr() &&
+ _srcValue == null &&
+ _charNodesValue == null)
+ {
+ assert (_firstChild instanceof Xobj.NodeXobj):
+ "wrong node type";
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * can one use the _nextSibling pointer to retrieve
+ * the next DOM sibling
+ * @return
+ */
+ final protected boolean isNextSiblingPtrDomUsable()
+ {
+ if (_charNodesAfter == null &&
+ _srcAfter == null)
+ {
+ assert (_nextSibling == null ||
+ _nextSibling instanceof Xobj.NodeXobj):
+ "wrong node type";
+ return true;
+ }
+ return false;
+ }
+
+
final Xobj lastAttr ( )
{
if (_firstChild == null || !_firstChild.isAttr())
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org