Project

Profile

Help

Revision 108d6534

Added by Michael Kay over 12 years ago

Further patch for bug 2454364 (shared-append evaluation)

View differences:

latest9.1/bj/net/sf/saxon/expr/ExpressionTool.java
352 352
            }
353 353

  
354 354
            case SHARED_APPEND_EXPRESSION: {
355
                Block block = (Block)exp;
356
                Expression base = block.getChildren()[0];
357
                Value baseVal;
358
                if (base instanceof Literal) {
359
                    baseVal = ((Literal)base).getValue();
360
                } else if (base instanceof VariableReference) {
361
                    baseVal = Value.asValue(evaluate(base, EVALUATE_VARIABLE, context, ref));
362
                    if (baseVal instanceof MemoClosure && ((MemoClosure)baseVal).isFullyRead()) {
363
                        baseVal = ((MemoClosure)baseVal).materialize();
364
                    }
365
                } else {
366
                    throw new AssertionError("base of shared append expression is of class " + base.getClass());
367
                }
368
                if (baseVal instanceof ShareableSequence && ((ShareableSequence)baseVal).isShareable()) {
369
                    List list = ((ShareableSequence)baseVal).getList();
370
                    SequenceIterator iter = block.getChildren()[1].iterate(context);
371
                    while (true) {
372
                        Item i = iter.next();
373
                        if (i == null) {
374
                            break;
355
                if (exp instanceof Block) {
356
                    Block block = (Block)exp;
357
                    Expression base = block.getChildren()[0];
358
                    Value baseVal;
359
                    if (base instanceof Literal) {
360
                        baseVal = ((Literal)base).getValue();
361
                    } else if (base instanceof VariableReference) {
362
                        baseVal = Value.asValue(evaluate(base, EVALUATE_VARIABLE, context, ref));
363
                        if (baseVal instanceof MemoClosure && ((MemoClosure)baseVal).isFullyRead()) {
364
                            baseVal = ((MemoClosure)baseVal).materialize();
375 365
                        }
376
                        list.add(i);
366
                    } else {
367
                        throw new AssertionError("base of shared append expression is of class " + base.getClass());
377 368
                    }
378
                    return new ShareableSequence(list);
379
                } else {
380
                    List list = new ArrayList(20);
381
                    SequenceIterator iter = baseVal.iterate();
382
                    while (true) {
383
                        Item i = iter.next();
384
                        if (i == null) {
385
                            break;
369
                    if (baseVal instanceof ShareableSequence && ((ShareableSequence)baseVal).isShareable()) {
370
                        List list = ((ShareableSequence)baseVal).getList();
371
                        SequenceIterator iter = block.getChildren()[1].iterate(context);
372
                        while (true) {
373
                            Item i = iter.next();
374
                            if (i == null) {
375
                                break;
376
                            }
377
                            list.add(i);
386 378
                        }
387
                        list.add(i);
388
                    }
389
                    iter = block.getChildren()[1].iterate(context);
390
                    while (true) {
391
                        Item i = iter.next();
392
                        if (i == null) {
393
                            break;
379
                        return new ShareableSequence(list);
380
                    } else {
381
                        List list = new ArrayList(20);
382
                        SequenceIterator iter = baseVal.iterate();
383
                        while (true) {
384
                            Item i = iter.next();
385
                            if (i == null) {
386
                                break;
387
                            }
388
                            list.add(i);
389
                        }
390
                        iter = block.getChildren()[1].iterate(context);
391
                        while (true) {
392
                            Item i = iter.next();
393
                            if (i == null) {
394
                                break;
395
                            }
396
                            list.add(i);
394 397
                        }
395
                        list.add(i);
398
                        return new ShareableSequence(list);
396 399
                    }
397
                    return new ShareableSequence(list);
400
                } else {
401
                    // it's not a Block: it must have been rewritten after deciding to use this evaluation mode
402
                    return SequenceExtent.makeSequenceExtent(exp.iterate(context));
398 403
                }
399 404
            }
400 405

  

Also available in: Unified diff