From: Piotr K. <pi...@id...> - 2004-05-28 00:07:31
|
My previous patch for appendChild was sadly incomplete; this one seems to work slightly better. It's still voodoo coding, mind you. I also include a minor patch to the NativeBroker.getRange, since its node list initial capacity was off by 1 due to inclusive boundaries. It will reduce array reallocation. Index: ElementImpl.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/dom/ElementImpl.java,v retrieving revision 1.33 diff -u -r1.33 ElementImpl.java --- ElementImpl.java 10 May 2004 11:22:39 -0000 1.33 +++ ElementImpl.java 27 May 2004 22:52:48 -0000 @@ -225,18 +225,24 @@ */ public Node appendChild(Node child) throws DOMException { DocumentImpl prevDoc = new DocumentImpl(ownerDocument); - Node node = null; - if (children == 0) - node = appendChild(firstChildID(), this, child, true); - else { - long last = lastChildID(); - node = - appendChild( - last + 1, - (NodeImpl) ownerDocument.getNode(last), - child, - true); + long childGid; + NodeImpl lastNode; + if (children == 0) { + childGid = firstChildID(); + lastNode = this; + } else { + childGid = lastChildID() + 1; + lastNode = getLastNode((NodeImpl) ownerDocument.getNode(childGid - 1)); + } + try { + checkTree(1); + } catch (EXistException e) { + throw new DOMException( + DOMException.INVALID_MODIFICATION_ERR, + "max. document size exceeded"); } + children++; + Node node = appendChild(childGid, lastNode, child, true); ownerDocument.broker.update(this); ownerDocument.broker.reindex(prevDoc, ownerDocument, null); try { @@ -909,10 +915,10 @@ prefix = (String) entry.getKey(); namespace = (String) entry.getValue(); if (prefix.length() == 0) { - buf.append("xmlns=\""); + buf.append(" xmlns=\""); buf.append(namespace); } else { - buf.append("xmlns:"); + buf.append(" xmlns:"); buf.append(prefix); buf.append("=\""); buf.append(namespace); @@ -923,7 +929,7 @@ } if (nodeName.getNamespaceURI().length() > 0 && (!namespaces.contains(nodeName.getNamespaceURI()))) { - buf.append("\" xmlns:").append(nodeName.getPrefix()).append("=\""); + buf.append(" xmlns:").append(nodeName.getPrefix()).append("=\""); buf.append(nodeName.getNamespaceURI()); buf.append("\" "); } Index: NativeBroker.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/NativeBroker.java,v retrieving revision 1.75 diff -u -r1.75 NativeBroker.java --- NativeBroker.java 25 May 2004 13:21:09 -0000 1.75 +++ NativeBroker.java 27 May 2004 22:50:38 -0000 @@ -1318,7 +1318,7 @@ *@return a list of nodes */ public NodeList getRange(final Document doc, final long first, final long last) { - NodeListImpl result = new NodeListImpl((int) (last - first)); + NodeListImpl result = new NodeListImpl((int) (last - first + 1)); for (long gid = first; gid <= last; gid++) { result.add(objectWith(doc, gid)); } |