@@ -761,44 +761,41 @@ protected function nthChild($groupSize, $elementInGroup, $lastChild = false)
761761 // though.
762762 $ parents = new SplObjectStorage ();
763763 $ matches = new SplObjectStorage ();
764+ $ index = new SplObjectStorage ();
764765
765- $ i = 0 ;
766766 foreach ($ this ->matches as $ item ) {
767767 $ parent = $ item ->parentNode ;
768768
769769 // Build up an array of all of children of this parent, and store the
770770 // index of each element for reference later. We only need to do this
771771 // once per parent, though.
772- if (! $ parents ->contains ($ parent )) {
772+ if (!$ parents ->contains ($ parent )) {
773773 $ c = 0 ;
774774 foreach ($ parent ->childNodes as $ child ) {
775775 // We only want nodes, and if this call is preceded by an element
776776 // selector, we only want to match elements with the same tag name.
777777 // !!! This last part is a grey area in the CSS 3 Selector spec. It seems
778778 // necessary to make the implementation match the examples in the spec. However,
779779 // jQuery 1.2 does not do this.
780- if ($ child ->nodeType == XML_ELEMENT_NODE && ($ this ->findAnyElement || $ child ->tagName == $ item ->tagName )) {
781- // This may break E_STRICT.
782- $ child ->nodeIndex = ++$ c ;
780+ if ($ child ->nodeType === XML_ELEMENT_NODE && ($ this ->findAnyElement || $ child ->tagName === $ item ->tagName )) {
781+ $ index ->attach ($ child , ++$ c );
783782 }
784783 }
785- // This may break E_STRICT.
786- $ parent ->numElements = $ c ;
787- $ parents ->attach ($ parent );
784+ $ parents ->attach ($ parent , $ c );
788785 }
789786
790787 // If we are looking for the last child, we count from the end of a list.
791788 // Note that we add 1 because CSS indices begin at 1, not 0.
792789 if ($ lastChild ) {
793- $ indexToMatch = $ item -> parentNode -> numElements - $ item -> nodeIndex + 1 ;
790+ $ indexToMatch = $ parents -> offsetGet ( $ item -> parentNode ) - $ index -> offsetGet ( $ item ) + 1 ;
794791 } // Otherwise we count from the beginning of the list.
795792 else {
796- $ indexToMatch = $ item -> nodeIndex ;
793+ $ indexToMatch = $ index -> offsetGet ( $ item ) ;
797794 }
798795
799796 // If group size is 0, then we return element at the right index.
800- if ($ groupSize == 0 ) {
801- if ($ indexToMatch == $ elementInGroup ) {
797+ if ($ groupSize === 0 ) {
798+ if ($ indexToMatch === $ elementInGroup ) {
802799 $ matches ->attach ($ item );
803800 }
804801 }
@@ -810,9 +807,6 @@ protected function nthChild($groupSize, $elementInGroup, $lastChild = false)
810807 $ matches ->attach ($ item );
811808 }
812809 }
813-
814- // Iterate.
815- ++$ i ;
816810 }
817811 $ this ->matches = $ matches ;
818812 }
@@ -950,45 +944,42 @@ protected function childAtIndex($index, $tagName = NULL) {
950944 protected function nthOfTypeChild ($ groupSize , $ elementInGroup , $ lastChild )
951945 {
952946 // EXPERIMENTAL: New in Quark. This should be substantially faster
953- // than the old (jQuery-ish) version. It still has E_STRICT violations
954- // though.
947+ // than the old (jQuery-ish) version.
955948 $ parents = new SplObjectStorage ();
956949 $ matches = new SplObjectStorage ();
950+ $ index = new SplObjectStorage ();
957951
958- $ i = 0 ;
959952 foreach ($ this ->matches as $ item ) {
960953 $ parent = $ item ->parentNode ;
961954
962955 // Build up an array of all of children of this parent, and store the
963956 // index of each element for reference later. We only need to do this
964957 // once per parent, though.
965- if (! $ parents ->contains ($ parent )) {
958+ if (!$ parents ->contains ($ parent )) {
966959 $ c = 0 ;
967960 foreach ($ parent ->childNodes as $ child ) {
968961 // This doesn't totally make sense, since the CSS 3 spec does not require that
969962 // this pseudo-class be adjoined to an element (e.g. ' :nth-of-type' is allowed).
970- if ($ child ->nodeType == XML_ELEMENT_NODE && $ child ->tagName == $ item ->tagName ) {
971- // This may break E_STRICT.
972- $ child ->nodeIndex = ++$ c ;
963+ if ($ child ->nodeType === XML_ELEMENT_NODE && $ child ->tagName === $ item ->tagName ) {
964+ $ index ->attach ($ child , ++$ c );
973965 }
974966 }
975- // This may break E_STRICT.
976- $ parent ->numElements = $ c ;
977- $ parents ->attach ($ parent );
967+
968+ $ parents ->attach ($ parent , $ c );
978969 }
979970
980971 // If we are looking for the last child, we count from the end of a list.
981972 // Note that we add 1 because CSS indices begin at 1, not 0.
982973 if ($ lastChild ) {
983- $ indexToMatch = $ item -> parentNode -> numElements - $ item -> nodeIndex + 1 ;
974+ $ indexToMatch = $ parents -> offsetGet ( $ item -> parentNode ) - $ index -> offsetGet ( $ item ) + 1 ;
984975 } // Otherwise we count from the beginning of the list.
985976 else {
986- $ indexToMatch = $ item -> nodeIndex ;
977+ $ indexToMatch = $ index -> offsetGet ( $ item ) ;
987978 }
988979
989980 // If group size is 0, then we return element at the right index.
990- if ($ groupSize == 0 ) {
991- if ($ indexToMatch == $ elementInGroup ) {
981+ if ($ groupSize === 0 ) {
982+ if ($ indexToMatch === $ elementInGroup ) {
992983 $ matches ->attach ($ item );
993984 }
994985 }
@@ -1000,9 +991,6 @@ protected function nthOfTypeChild($groupSize, $elementInGroup, $lastChild)
1000991 $ matches ->attach ($ item );
1001992 }
1002993 }
1003-
1004- // Iterate.
1005- ++$ i ;
1006994 }
1007995 $ this ->matches = $ matches ;
1008996 }
0 commit comments