| 2633 | bySet = setMatchers.length > 0, |
| 2634 | byElement = elementMatchers.length > 0, |
| 2635 | superMatcher = function( seed, context, xml, results, expandContext ) { |
| 2636 | var elem, j, matcher, |
| 2637 | setMatched = [], |
| 2638 | matchedCount = 0, |
| 2639 | i = "0", |
| 2640 | unmatched = seed && [], |
| 2641 | outermost = expandContext != null, |
| 2642 | contextBackup = outermostContext, |
| 2643 | // We must always have either seed elements or context |
| 2644 | elems = seed || byElement && Expr.find["TAG"]( "*", expandContext && context.parentNode || context ), |
| 2645 | // Use integer dirruns iff this is the outermost matcher |
| 2646 | dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1); |
| 2647 | |
| 2648 | if ( outermost ) { |
| 2649 | outermostContext = context !== document && context; |
| 2650 | cachedruns = matcherCachedRuns; |
| 2651 | } |
| 2652 | |
| 2653 | // Add elements passing elementMatchers directly to results |
| 2654 | // Keep `i` a string if there are no elements so `matchedCount` will be "00" below |
| 2655 | for ( ; (elem = elems[i]) != null; i++ ) { |
| 2656 | if ( byElement && elem ) { |
| 2657 | j = 0; |
| 2658 | while ( (matcher = elementMatchers[j++]) ) { |
| 2659 | if ( matcher( elem, context, xml ) ) { |
| 2660 | results.push( elem ); |
| 2661 | break; |
| 2662 | } |
| 2663 | } |
| 2664 | if ( outermost ) { |
| 2665 | dirruns = dirrunsUnique; |
| 2666 | cachedruns = ++matcherCachedRuns; |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | // Track unmatched elements for set filters |
| 2671 | if ( bySet ) { |
| 2672 | // They will have gone through all possible matchers |
| 2673 | if ( (elem = !matcher && elem) ) { |
| 2674 | matchedCount--; |
| 2675 | } |
| 2676 | |
| 2677 | // Lengthen the array for every element, matched or not |
| 2678 | if ( seed ) { |
| 2679 | unmatched.push( elem ); |
| 2680 | } |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | // Apply set filters to unmatched elements |
| 2685 | matchedCount += i; |
| 2686 | if ( bySet && i !== matchedCount ) { |
| 2687 | j = 0; |
| 2688 | while ( (matcher = setMatchers[j++]) ) { |
| 2689 | matcher( unmatched, setMatched, context, xml ); |
| 2690 | } |
| 2691 | |
| 2692 | if ( seed ) { |