Project

Profile

Help

Revision ba5b8a50

Added by Michael Kay over 7 years ago

Fix bug 2092

View differences:

latest9.5/hej/net/sf/saxon/trans/KeyManager.java
378 378
                    // otherwise, we need to insert the node at the correct
379 379
                    // position in document order. This code does an insertion sort:
380 380
                    // not ideal for performance, but it's very unusual to have more than
381
                    // one key definition for a key.
381
                    // one key definition for a key. We start looking at the end because
382
                    // it's most likely that the new node will come after all the others.
383
                    // See bug 2092 in saxonica.plan.io
382 384
                    LocalOrderComparer comparer = LocalOrderComparer.getInstance();
383 385
                    boolean found = false;
384
                    for (int i=0; i<nodes.size(); i++) {
386
                    for (int i=nodes.size()-1; i>=0; i--) {
385 387
                        int d = comparer.compare(curr, nodes.get(i));
386
                        if (d<=0) {
388
                        if (d>=0) {
387 389
                            if (d==0) {
388 390
                                // node already in list; do nothing
389 391
                            } else {
390 392
                                // add the node at this position
391
                                nodes.add(i, curr);
393
                                nodes.add(i+1, curr);
392 394
                            }
393 395
                            found = true;
394 396
                            break;
395 397
                        }
396 398
                        // else continue round the loop
397 399
                    }
398
                    // if we're still here, add the new node at the end
400
                    // if we're still here, add the new node at the start
399 401
                    if (!found) {
400
                        nodes.add(curr);
402
                        nodes.add(0, curr);
401 403
                    }
402 404
                }
403 405
            }

Also available in: Unified diff