From 546a0f756104fc9ae89207750c6a9eb566f5ea63 Mon Sep 17 00:00:00 2001
From: "arseny.kapoulkine"
 <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>
Date: Thu, 22 Jul 2010 07:59:11 +0000
Subject: [PATCH] xml_node::find_node is now not recursive

git-svn-id: http://pugixml.googlecode.com/svn/trunk@614 99668b35-9821-0410-8761-19e4c4f06640
---
 src/pugixml.hpp | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/pugixml.hpp b/src/pugixml.hpp
index 81f5769e..6a5f7e46 100644
--- a/src/pugixml.hpp
+++ b/src/pugixml.hpp
@@ -1343,15 +1343,19 @@ namespace pugi
 		{
 			if (!_root) return xml_node();
 
-			for (xml_node node = first_child(); node; node = node.next_sibling())
+			xml_node cur = first_child();
+			
+			while (cur._root && cur._root != _root)
 			{
-				if (pred(node))
-					return node;
-				
-				if (node.first_child())
+				if (pred(cur)) return cur;
+
+				if (cur.first_child()) cur = cur.first_child();
+				else if (cur.next_sibling()) cur = cur.next_sibling();
+				else
 				{
-					xml_node found = node.find_node(pred);
-					if (found) return found;
+					while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
+
+					if (cur._root != _root) cur = cur.next_sibling();
 				}
 			}
 
-- 
GitLab