| 2706 | } |
| 2707 | |
| 2708 | function matcherFromGroupMatchers( elementMatchers, setMatchers ) { |
| 2709 | // A counter to specify which element is currently being matched |
| 2710 | var matcherCachedRuns = 0, |
| 2711 | bySet = setMatchers.length > 0, |
| 2712 | byElement = elementMatchers.length > 0, |
| 2713 | superMatcher = function( seed, context, xml, results, expandContext ) { |
| 2714 | var elem, j, matcher, |
| 2715 | setMatched = [], |
| 2716 | matchedCount = 0, |
| 2717 | i = "0", |
| 2718 | unmatched = seed && [], |
| 2719 | outermost = expandContext != null, |
| 2720 | contextBackup = outermostContext, |
| 2721 | // We must always have either seed elements or context |
| 2722 | elems = seed || byElement && Expr.find["TAG"]( "*", expandContext && context.parentNode || context ), |
| 2723 | // Use integer dirruns iff this is the outermost matcher |
| 2724 | dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1); |
| 2725 | |
| 2726 | if ( outermost ) { |
| 2727 | outermostContext = context !== document && context; |
| 2728 | cachedruns = matcherCachedRuns; |
| 2729 | } |
| 2730 | |
| 2731 | // Add elements passing elementMatchers directly to results |
| 2732 | // Keep `i` a string if there are no elements so `matchedCount` will be "00" below |
| 2733 | for ( ; (elem = elems[i]) != null; i++ ) { |
| 2734 | if ( byElement && elem ) { |
| 2735 | j = 0; |
| 2736 | while ( (matcher = elementMatchers[j++]) ) { |
| 2737 | if ( matcher( elem, context, xml ) ) { |
| 2738 | results.push( elem ); |
| 2739 | break; |
| 2740 | } |
| 2741 | } |
| 2742 | if ( outermost ) { |
| 2743 | dirruns = dirrunsUnique; |
| 2744 | cachedruns = ++matcherCachedRuns; |
| 2745 | } |
| 2746 | } |
| 2747 | |
| 2748 | // Track unmatched elements for set filters |
| 2749 | if ( bySet ) { |
| 2750 | // They will have gone through all possible matchers |
| 2751 | if ( (elem = !matcher && elem) ) { |
| 2752 | matchedCount--; |
| 2753 | } |
| 2754 | |
| 2755 | // Lengthen the array for every element, matched or not |
| 2756 | if ( seed ) { |
| 2757 | unmatched.push( elem ); |
| 2758 | } |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | // Apply set filters to unmatched elements |
| 2763 | matchedCount += i; |
| 2764 | if ( bySet && i !== matchedCount ) { |
| 2765 | j = 0; |