Skip to content

Commit

Permalink
[performance] Cleanup method: Sequence.destroy is called much too oft…
Browse files Browse the repository at this point in the history
…en inside FLWOR execution. Only call it once when a variable actually runs out of scope.
  • Loading branch information
wolfgangmm committed May 24, 2014
1 parent dbd84f4 commit 7b4b607
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/org/exist/xquery/XQueryContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -2576,16 +2576,13 @@ public void popLocalVariables(LocalVariable var) {
*/
public void popLocalVariables(LocalVariable var, Sequence resultSeq)
{
final LocalVariable end = contextStack.isEmpty() ? null : contextStack.peek();

for( LocalVariable old = lastVar; old != null; old = old.before ) {

if( old == end ) {
break;
// clear all variables registered after var. they should be out of scope.
LocalVariable outOfScope = lastVar;
while (outOfScope != var) {
if (!outOfScope.isClosureVar()) {
outOfScope.destroy(this, resultSeq);
}
// reset variable unless it is a closure variable (inherited from context)
if (!old.isClosureVar())
{old.destroy(this, resultSeq);}
outOfScope = outOfScope.before;
}
if( var != null ) {
var.after = null;
Expand Down
8 changes: 7 additions & 1 deletion src/org/exist/xquery/value/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.exist.numbering.NodeId;
import org.exist.storage.DBBroker;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -57,7 +58,12 @@ public interface Item {
*
*/
public Sequence toSequence();


/**
* Clean up any resources used by the items in this sequence.
*/
void destroy(XQueryContext context, Sequence contextSequence);

/**
* Convert this item into an atomic value, whose type corresponds to
* the specified target type. requiredType should be one of the type
Expand Down
3 changes: 2 additions & 1 deletion src/org/exist/xquery/value/ValueSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private void expand() {
@Override
public void destroy(XQueryContext context, Sequence contextSequence) {
for (int i = 0; i <= size; i++) {
((Sequence)values[i]).destroy(context, contextSequence);
values[i].destroy(context, contextSequence);
}
}

Expand All @@ -365,6 +365,7 @@ public boolean containsValue(AtomicValue value) {
}
return false;
}

public void sortInDocumentOrder() {
if (size == UNSET_SIZE)
{return;}
Expand Down

0 comments on commit 7b4b607

Please sign in to comment.