From: Wolfgang M. M. <wol...@us...> - 2004-03-25 13:01:38
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xquery In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24347/src/org/exist/xquery Modified Files: XQueryContext.java LocationStep.java Added Files: DescendantSelector.java DescendantOrSelfSelector.java ChildSelector.java NodeSelector.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: LocationStep.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/LocationStep.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** LocationStep.java 25 Feb 2004 15:31:57 -0000 1.2 --- LocationStep.java 25 Mar 2004 12:50:50 -0000 1.3 *************** *** 197,220 **** } else { DocumentSet docs = contextSet.getDocumentSet(); ! if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { ! currentDocs = docs; ! currentSet = ! (NodeSet) context.getBroker().getAttributesByName( ! currentDocs, test.getName()); ! } ! if (axis == Constants.DESCENDANT_ATTRIBUTE_AXIS) { ! result = ! currentSet.selectAncestorDescendant( ! contextSet, ! NodeSet.DESCENDANT, ! inPredicate); ! ! } else { ! result = ! currentSet.selectParentChild( ! contextSet, ! NodeSet.DESCENDANT, ! inPredicate); ! } } return result; --- 197,208 ---- } else { DocumentSet docs = contextSet.getDocumentSet(); ! NodeSelector selector; ! if(axis == Constants.DESCENDANT_ATTRIBUTE_AXIS) ! selector = new DescendantSelector(contextSet, inPredicate); ! else ! selector = new ChildSelector(contextSet, inPredicate); ! result = context.getBroker().findElementsByTagName( ! ElementValue.ATTRIBUTE, docs, test.getName(), selector ! ); } return result; *************** *** 231,244 **** } else { DocumentSet docs = contextSet.getDocumentSet(); ! if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { ! currentDocs = docs; ! currentSet = ! (NodeSet) context.getBroker().findElementsByTagName( ! ElementValue.ELEMENT, ! currentDocs, ! test.getName()); ! } ! NodeSet result = ! currentSet.selectParentChild(contextSet, NodeSet.DESCENDANT, inPredicate); return result; } --- 219,226 ---- } else { DocumentSet docs = contextSet.getDocumentSet(); ! NodeSelector selector = new ChildSelector(contextSet, inPredicate); ! NodeSet result = context.getBroker().findElementsByTagName( ! ElementValue.ELEMENT, docs, test.getName(), selector ! ); return result; } *************** *** 255,270 **** } else { DocumentSet docs = contextSet.getDocumentSet(); ! if (currentSet == null || currentDocs == null || !(docs.equals(currentDocs))) { ! currentDocs = docs; ! currentSet = ! (NodeSet) context.getBroker().findElementsByTagName( ! ElementValue.ELEMENT, currentDocs, ! test.getName()); ! } ! NodeSet result = currentSet.selectAncestorDescendant( ! contextSet, ! NodeSet.DESCENDANT, ! axis == Constants.DESCENDANT_SELF_AXIS, ! inPredicate); return result; } --- 237,246 ---- } else { DocumentSet docs = contextSet.getDocumentSet(); ! NodeSelector selector = axis == Constants.DESCENDANT_SELF_AXIS ? ! new DescendantOrSelfSelector(contextSet, inPredicate) : ! new DescendantSelector(contextSet, inPredicate); ! NodeSet result = context.getBroker().findElementsByTagName( ! ElementValue.ELEMENT, docs, test.getName(), selector ! ); return result; } *************** *** 282,286 **** (NodeSet) context.getBroker().findElementsByTagName( ElementValue.ELEMENT, currentDocs, ! test.getName()); } result = contextSet.selectSiblings( --- 258,262 ---- (NodeSet) context.getBroker().findElementsByTagName( ElementValue.ELEMENT, currentDocs, ! test.getName(), null); } result = contextSet.selectSiblings( *************** *** 328,332 **** (NodeSet) context.getBroker().findElementsByTagName( ElementValue.ELEMENT, currentDocs, ! test.getName()); } result = contextSet.selectFollowing(currentSet); --- 304,308 ---- (NodeSet) context.getBroker().findElementsByTagName( ElementValue.ELEMENT, currentDocs, ! test.getName(), null); } result = contextSet.selectFollowing(currentSet); *************** *** 346,350 **** (NodeSet) context.getBroker().findElementsByTagName( ElementValue.ELEMENT, currentDocs, ! test.getName()); } result = --- 322,326 ---- (NodeSet) context.getBroker().findElementsByTagName( ElementValue.ELEMENT, currentDocs, ! test.getName(), null); } result = *************** *** 384,387 **** --- 360,364 ---- super.resetState(); currentSet = null; + currentDocs = null; cachedContext = null; cachedResult = null; --- NEW FILE: NodeSelector.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-03 Wolfgang M. Meier * wol...@ex... * http://exist.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: NodeSelector.java,v 1.1 2004/03/25 12:50:50 wolfgang_m Exp $ */ package org.exist.xquery; import org.exist.dom.NodeProxy; /** * @author Wolfgang Meier (wol...@ex...) */ public interface NodeSelector { public boolean match(NodeProxy node); } --- NEW FILE: DescendantSelector.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-03 Wolfgang M. Meier * wol...@ex... * http://exist.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: DescendantSelector.java,v 1.1 2004/03/25 12:50:50 wolfgang_m Exp $ */ package org.exist.xquery; import org.exist.dom.NodeProxy; import org.exist.dom.NodeSet; /** * @author Wolfgang Meier (wol...@ex...) */ public class DescendantSelector implements NodeSelector { protected NodeSet context; protected boolean rememberContext = false; public DescendantSelector(NodeSet contextSet, boolean rememberContext) { this.context = contextSet; this.rememberContext = rememberContext; } /* (non-Javadoc) * @see org.exist.xquery.NodeSelector#match(org.exist.dom.NodeProxy) */ public boolean match(NodeProxy node) { NodeProxy p; if((p = context.parentWithChild(node.doc, node.gid, false, false, -1)) != null) { if (rememberContext) node.addContextNode(p); else node.copyContext(p); return true; } return false; } } Index: XQueryContext.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/XQueryContext.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** XQueryContext.java 8 Mar 2004 11:21:22 -0000 1.8 --- XQueryContext.java 25 Mar 2004 12:50:50 -0000 1.9 *************** *** 296,299 **** --- 296,306 ---- } + public void reset() { + builder = null; + staticDocuments = null; + variableStack.clear(); + fragmentStack.clear(); + } + /** * Returns true if whitespace between constructed element nodes --- NEW FILE: DescendantOrSelfSelector.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-03 Wolfgang M. Meier * wol...@ex... * http://exist.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: DescendantOrSelfSelector.java,v 1.1 2004/03/25 12:50:50 wolfgang_m Exp $ */ package org.exist.xquery; import org.exist.dom.NodeProxy; import org.exist.dom.NodeSet; /** * @author Wolfgang Meier (wol...@ex...) */ public class DescendantOrSelfSelector extends DescendantSelector { public DescendantOrSelfSelector(NodeSet contextSet, boolean rememberContext) { super(contextSet, rememberContext); } /* (non-Javadoc) * @see org.exist.xquery.NodeSelector#match(org.exist.dom.NodeProxy) */ public boolean match(NodeProxy node) { NodeProxy p; if((p = context.parentWithChild(node.doc, node.gid, false, true, -1)) != null) { if (rememberContext) node.addContextNode(p); else node.copyContext(p); return true; } return false; } } --- NEW FILE: ChildSelector.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-03 Wolfgang M. Meier * wol...@ex... * http://exist.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: ChildSelector.java,v 1.1 2004/03/25 12:50:50 wolfgang_m Exp $ */ package org.exist.xquery; import org.exist.dom.NodeProxy; import org.exist.dom.NodeSet; /** * @author Wolfgang Meier (wol...@ex...) */ public class ChildSelector implements NodeSelector { private NodeSet context; private boolean rememberContext = false; public ChildSelector(NodeSet contextSet, boolean rememberContext) { this.context = contextSet; this.rememberContext = rememberContext; } /* (non-Javadoc) * @see org.exist.xquery.NodeSelector#match(org.exist.dom.NodeProxy) */ public boolean match(NodeProxy node) { NodeProxy p; if((p = context.parentWithChild(node.doc, node.gid, true, false, -1)) != null) { if (rememberContext) node.addContextNode(p); else node.copyContext(p); return true; } return false; } } |