Corrected XPath iterator for ancestor-or-self axes for runaway behaviour
authorDavid Eisner <david.eisner@oriel.oxon.org>
Thu, 21 Jul 2011 22:19:00 +0000 (23:19 +0100)
committerDavid Eisner <david.eisner@oriel.oxon.org>
Thu, 21 Jul 2011 22:19:00 +0000 (23:19 +0100)
Adding a test case for ancestor-or-self along the lines of the existing one for ancestor showed runaway, memory-eating behaviour. In changing CollectResults to remove the livelock, it seemed simplest to remove the extra yield of the root from MoveNextCore. I was unable to ascertain a good reason for producing this element in this special way compared to the AncestorIterator.

mcs/class/System.XML/System.Xml.XPath/Iterator.cs

index b1c7f8d147ffd70c3c90b62dc02d4e9d81dbbe05..923bfc193bddd6b402e8c6d4c26204c017361980 100644 (file)
@@ -491,26 +491,15 @@ namespace System.Xml.XPath
                        navigators = new ArrayList ();
 
                        XPathNavigator ancestors = startPosition.Clone ();
-                       if (!ancestors.MoveToParent ())
-                               return;
-                       while (ancestors.NodeType != XPathNodeType.Root) {
+                       while (ancestors.NodeType != XPathNodeType.Root && ancestors.MoveToParent ())
                                navigators.Add (ancestors.Clone ());
-                               ancestors.MoveToParent ();
-                       }
                        currentPosition = navigators.Count;
                }
 
                public override bool MoveNextCore ()
                {
-                       if (navigators == null) {
+                       if (navigators == null)
                                CollectResults ();
-                               if (startPosition.NodeType != XPathNodeType.Root) {
-                                       // First time it returns Root
-                                       _nav.MoveToRoot ();
-//                                     Current.MoveTo (_nav);
-                                       return true;
-                               }
-                       }
                        if (currentPosition == -1)
                                return false;
                        if (currentPosition-- == 0) {