From: Wolfgang M. M. <wol...@us...> - 2004-03-25 13:01:37
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/dom In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24347/src/org/exist/dom Modified Files: AbstractNodeSet.java ExtArrayNodeSet.java Log Message: * NativeBroker.findElementsByTagName now directly checks child, descendant and descendant-or-self relations by calling a passed instance of class NodeSelector. This saves one processing step when processing path expressions and reduces memory consumption. * clear the XQueryContext before putting a compiled expression into cache. Index: AbstractNodeSet.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/dom/AbstractNodeSet.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AbstractNodeSet.java 5 Mar 2004 16:15:47 -0000 1.13 --- AbstractNodeSet.java 25 Mar 2004 12:50:49 -0000 1.14 *************** *** 444,448 **** for (Iterator i = iterator(); i.hasNext();) { n = (NodeProxy) i.next(); ! p = al.parentWithChild(n.doc, n.gid, false, includeSelf); if (p != null) { if ((temp = result.get(p)) == null) { --- 444,448 ---- for (Iterator i = iterator(); i.hasNext();) { n = (NodeProxy) i.next(); ! p = al.parentWithChild(n.doc, n.gid, false, includeSelf, -1); if (p != null) { if ((temp = result.get(p)) == null) { Index: ExtArrayNodeSet.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/dom/ExtArrayNodeSet.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ExtArrayNodeSet.java 4 Mar 2004 10:09:37 -0000 1.12 --- ExtArrayNodeSet.java 25 Mar 2004 12:50:49 -0000 1.13 *************** *** 22,26 **** import java.util.Iterator; - import org.exist.util.FastQSort; import org.exist.util.Range; --- 22,25 ---- *************** *** 58,65 **** private boolean isSorted = false; private boolean isInDocumentOrder = false; - private int lastDoc = -1; private Part lastPart = null; - private int state = 0; --- 57,62 ---- *************** *** 67,79 **** this.map = new Int2ObjectHashMap(512); } ! /** ! * Constructor for ExtArrayNodeSet. * ! * The first argument specifies the expected number of documents in ! * this node set. The second int argument specifies the default ! * array size, which is used whenever a new array has to be allocated for ! * nodes. The default array size can be overwritten by the sizeHint ! * argument passed to {@link #add(NodeProxy, int). * * @param initialDocsCount --- 64,76 ---- this.map = new Int2ObjectHashMap(512); } ! /** ! * Constructor for ExtArrayNodeSet. * ! * The first argument specifies the expected number of documents in this ! * node set. The second int argument specifies the default array size, ! * which is used whenever a new array has to be allocated for nodes. The ! * default array size can be overwritten by the sizeHint argument passed to ! * {@link #add(NodeProxy, int). * * @param initialDocsCount *************** *** 88,94 **** this(512, initialArraySize); } ! public void add(NodeProxy proxy) { ! getPart(proxy.doc.docId, true, initalSize).add(proxy); ++size; isSorted = false; --- 85,91 ---- this(512, initialArraySize); } ! public void add(NodeProxy proxy) { ! getPart(proxy.doc, true, initalSize).add(proxy); ++size; isSorted = false; *************** *** 105,109 **** */ public void add(NodeProxy proxy, int sizeHint) { ! getPart(proxy.doc.docId, true, sizeHint > -1 ? sizeHint : initalSize).add(proxy); ++size; isSorted = false; --- 102,107 ---- */ public void add(NodeProxy proxy, int sizeHint) { ! getPart(proxy.doc, true, sizeHint > -1 ? sizeHint : initalSize).add( ! proxy); ++size; isSorted = false; *************** *** 117,134 **** public int getSizeHint(DocumentImpl doc) { ! Part part = getPart(doc.docId, false, 0); return part == null ? -1 : part.length; } ! private Part getPart(int docId, boolean create, int sizeHint) { ! if (docId == lastDoc && lastPart != null) return lastPart; ! Part part = (Part) map.get(docId); if (part == null && create) { ! part = new Part(sizeHint); ! map.put(docId, part); } lastPart = part; ! lastDoc = docId; return part; } --- 115,132 ---- public int getSizeHint(DocumentImpl doc) { ! Part part = getPart(doc, false, 0); return part == null ? -1 : part.length; } ! private Part getPart(DocumentImpl doc, boolean create, int sizeHint) { ! if (doc.docId == lastDoc && lastPart != null) return lastPart; ! Part part = (Part) map.get(doc.docId); if (part == null && create) { ! part = new Part(sizeHint, doc); ! map.put(doc.docId, part); } lastPart = part; ! lastDoc = doc.docId; return part; } *************** *** 179,183 **** */ public boolean contains(DocumentImpl doc, long nodeId) { ! final Part part = getPart(doc.docId, false, 0); return part == null ? false : part.contains(nodeId); } --- 177,181 ---- */ public boolean contains(DocumentImpl doc, long nodeId) { ! final Part part = getPart(doc, false, 0); return part == null ? false : part.contains(nodeId); } *************** *** 189,193 **** */ public boolean contains(NodeProxy proxy) { ! final Part part = getPart(proxy.doc.docId, false, 0); return part == null ? false : part.contains(proxy.gid); } --- 187,191 ---- */ public boolean contains(NodeProxy proxy) { ! final Part part = getPart(proxy.doc, false, 0); return part == null ? false : part.contains(proxy.gid); } *************** *** 199,203 **** */ public void addAll(NodeSet other) { ! for (Iterator i = other.iterator(); i.hasNext(); ) { add((NodeProxy) i.next()); } --- 197,201 ---- */ public void addAll(NodeSet other) { ! for (Iterator i = other.iterator(); i.hasNext();) { add((NodeProxy) i.next()); } *************** *** 210,214 **** */ public int getLength() { ! sort(); // sort to remove duplicates return size; } --- 208,212 ---- */ public int getLength() { ! sort(); // sort to remove duplicates return size; } *************** *** 233,237 **** int count = 0; Part part; ! for (Iterator i = map.valueIterator(); i.hasNext(); ) { part = (Part) i.next(); if (count + part.length > pos) --- 231,235 ---- int count = 0; Part part; ! for (Iterator i = map.valueIterator(); i.hasNext();) { part = (Part) i.next(); if (count + part.length > pos) *************** *** 248,252 **** */ public NodeProxy get(NodeProxy p) { ! final Part part = getPart(p.doc.docId, false, 0); return part == null ? null : part.get(p.gid); } --- 246,250 ---- */ public NodeProxy get(NodeProxy p) { ! final Part part = getPart(p.doc, false, 0); return part == null ? null : part.get(p.gid); } *************** *** 259,263 **** public NodeProxy get(DocumentImpl doc, long nodeId) { sort(); ! final Part part = getPart(doc.docId, false, 0); return part == null ? null : part.get(nodeId); } --- 257,261 ---- public NodeProxy get(DocumentImpl doc, long nodeId) { sort(); ! final Part part = getPart(doc, false, 0); return part == null ? null : part.get(nodeId); } *************** *** 279,283 **** */ public void remove(NodeProxy node) { ! final Part part = getPart(node.doc.getDocId(), false, 0); if (part == null) return; --- 277,281 ---- */ public void remove(NodeProxy node) { ! final Part part = getPart(node.doc, false, 0); if (part == null) return; *************** *** 289,299 **** public NodeSet getRange(DocumentImpl doc, long lower, long upper) { ! final Part part = getPart(doc.docId, false, 0); return part.getRange(lower, upper); } public NodeSet hasChildrenInSet(NodeProxy parent, int mode, ! boolean rememberContext) { ! final Part part = getPart(parent.doc.docId, false, 0); if (part == null) return new ArraySet(1); --- 287,297 ---- public NodeSet getRange(DocumentImpl doc, long lower, long upper) { ! final Part part = getPart(doc, false, 0); return part.getRange(lower, upper); } public NodeSet hasChildrenInSet(NodeProxy parent, int mode, ! boolean rememberContext) { ! final Part part = getPart(parent.doc, false, 0); if (part == null) return new ArraySet(1); *************** *** 307,311 **** Part part; size = 0; ! for (Iterator i = map.valueIterator(); i.hasNext(); ) { part = (Part) i.next(); part.sort(); --- 305,309 ---- Part part; size = 0; ! for (Iterator i = map.valueIterator(); i.hasNext();) { part = (Part) i.next(); part.sort(); *************** *** 320,328 **** public final void sortInDocumentOrder() { // long start = System.currentTimeMillis(); ! if(isInDocumentOrder) return; Part part; size = 0; ! for (Iterator i = map.valueIterator(); i.hasNext(); ) { part = (Part) i.next(); part.sortInDocumentOrder(); --- 318,326 ---- public final void sortInDocumentOrder() { // long start = System.currentTimeMillis(); ! if (isInDocumentOrder) return; Part part; size = 0; ! for (Iterator i = map.valueIterator(); i.hasNext();) { part = (Part) i.next(); part.sortInDocumentOrder(); *************** *** 342,346 **** public void setSelfAsContext() { Part part; ! for (Iterator i = map.valueIterator(); i.hasNext(); ) { part = (Part) i.next(); part.setSelfAsContext(); --- 340,344 ---- public void setSelfAsContext() { Part part; ! for (Iterator i = map.valueIterator(); i.hasNext();) { part = (Part) i.next(); part.setSelfAsContext(); *************** *** 348,351 **** --- 346,356 ---- } + public NodeProxy parentWithChild(DocumentImpl doc, long gid, + boolean directParent, + boolean includeSelf, int level) { + Part part = getPart(doc, false, -1); + return part == null ? null : part.parentWithChild(gid, directParent, includeSelf, level); + } + public DocumentSet getDocumentSet() { if (!isSorted) *************** *** 354,358 **** DocumentSet ds = new DocumentSet(); DocumentImpl doc, last = null; ! for (Iterator i = map.valueIterator(); i.hasNext(); ) { part = (Part) i.next(); if (!isSorted) { --- 359,363 ---- DocumentSet ds = new DocumentSet(); DocumentImpl doc, last = null; ! for (Iterator i = map.valueIterator(); i.hasNext();) { part = (Part) i.next(); if (!isSorted) { *************** *** 388,399 **** return state; } - private static class Part { NodeProxy array[]; int length = 0; ! Part(int initialSize) { array = new NodeProxy[initialSize]; } --- 393,405 ---- return state; } private static class Part { NodeProxy array[]; + DocumentImpl doc; int length = 0; ! Part(int initialSize, DocumentImpl myDoc) { array = new NodeProxy[initialSize]; + doc = myDoc; } *************** *** 441,445 **** return null; } ! void sort() { FastQSort.sortByNodeId(array, 0, length - 1); --- 447,451 ---- return null; } ! void sort() { FastQSort.sortByNodeId(array, 0, length - 1); *************** *** 461,466 **** * itself is contained in the node set. */ ! NodeProxy parentWithChild(DocumentImpl doc, long gid, ! boolean directParent, boolean includeSelf, int level) { NodeProxy temp; if (includeSelf && (temp = get(gid)) != null) --- 467,472 ---- * itself is contained in the node set. */ ! public NodeProxy parentWithChild(long gid, boolean directParent, ! boolean includeSelf, int level) { NodeProxy temp; if (includeSelf && (temp = get(gid)) != null) *************** *** 470,474 **** while (gid > 0) { gid = XMLUtil.getParentId(doc, gid, level); - if ((temp = get(gid)) != null) return temp; --- 476,479 ---- *************** *** 491,495 **** */ NodeSet getChildrenInSet(NodeProxy parent, int mode, ! boolean rememberContext) { NodeSet result = new ExtArrayNodeSet(); // get the range of node ids reserved for children of the parent --- 496,500 ---- */ NodeSet getChildrenInSet(NodeProxy parent, int mode, ! boolean rememberContext) { NodeSet result = new ExtArrayNodeSet(); // get the range of node ids reserved for children of the parent *************** *** 514,522 **** if (low > high) return result; // no node found - // find the first child node in the range while (mid > 0 && array[mid - 1].gid >= range.getStart()) --mid; - // walk through the range of child nodes we found for (int i = mid; i < length && array[i].gid <= range.getEnd(); i++) { --- 519,525 ---- *************** *** 561,565 **** if (low > high) return result; // no node found - // find the first child node in the range while (mid > 0 && array[mid - 1].gid >= lower) --- 564,567 ---- *************** *** 616,620 **** } } - private class ExtArrayIterator implements Iterator, SequenceIterator { --- 618,621 ---- |