use of org.exist.xquery.value.AtomicValue in project exist by eXist-db.
the class GeneralComparison method nodeSetCompare.
/**
* Optimized implementation, which can be applied if the left operand returns a node set. In this case, the left expression is executed first. All
* matching context nodes are then passed to the right expression.
*
* @param nodes DOCUMENT ME!
* @param contextSequence DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws XPathException DOCUMENT ME!
*/
protected Sequence nodeSetCompare(NodeSet nodes, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().message(this, Profiler.OPTIMIZATION_FLAGS, "OPTIMIZATION CHOICE", "nodeSetCompare");
}
if (LOG.isTraceEnabled()) {
LOG.trace("No index: fall back to nodeSetCompare");
}
final long start = System.currentTimeMillis();
final NodeSet result = new NewArrayNodeSet();
final Collator collator = getCollator(contextSequence);
if ((contextSequence != null) && !contextSequence.isEmpty() && !contextSequence.getDocumentSet().contains(nodes.getDocumentSet())) {
for (final NodeProxy item : nodes) {
ContextItem context = item.getContext();
if (context == null) {
throw (new XPathException(this, "Internal error: context node missing"));
}
final AtomicValue lv = item.atomize();
do {
final Sequence rs = getRight().eval(context.getNode().toSequence());
for (final SequenceIterator i2 = Atomize.atomize(rs).iterate(); i2.hasNext(); ) {
final AtomicValue rv = i2.nextItem().atomize();
if (compareAtomic(collator, lv, rv)) {
result.add(item);
}
}
} while ((context = context.getNextDirect()) != null);
}
} else {
for (final NodeProxy item : nodes) {
final AtomicValue lv = item.atomize();
final Sequence rs = getRight().eval(contextSequence);
for (final SequenceIterator i2 = Atomize.atomize(rs).iterate(); i2.hasNext(); ) {
final AtomicValue rv = i2.nextItem().atomize();
if (compareAtomic(collator, lv, rv)) {
result.add(item);
}
}
}
}
if (context.getProfiler().traceFunctions()) {
context.getProfiler().traceIndexUsage(context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.NO_INDEX, System.currentTimeMillis() - start);
}
return (result);
}
Aggregations