Index: C:/xampp/htdocs/wordpress_trunk/wp-includes/post.php
===================================================================
--- C:/xampp/htdocs/wordpress_trunk/wp-includes/post.php	(revision 11972)
+++ C:/xampp/htdocs/wordpress_trunk/wp-includes/post.php	(working copy)
@@ -2129,27 +2129,49 @@
 
 /**
  * Retrieve child pages from list of pages matching page ID.
+ * It returns the entire list of nested descendant pages rooted from page_id
  *
- * Matches against the pages parameter against the page ID. Also matches all
- * children for the same to retrieve all children of a page. Does not make any
- * SQL queries to get the children.
- *
  * @since 1.5.1
  *
  * @param int $page_id Page ID.
  * @param array $pages List of pages' objects.
  * @return array
  */
-function &get_page_children($page_id, $pages) {
-	$page_list = array();
-	foreach ( (array) $pages as $page ) {
-		if ( $page->post_parent == $page_id ) {
-			$page_list[] = $page;
-			if ( $children = get_page_children($page->ID, $pages) )
-				$page_list = array_merge($page_list, $children);
+function &get_page_children( $page_id, &$pages ) {
+	
+	/*
+	 * use auxiliary array structure to store the parent-children relations,
+	 * which allow O(1) per lookup, and gives O(N) overall complexity
+	 * ex: children[10][] contains all the children pages whose parent is 10
+	 */
+	 $children = array(); 
+	 foreach ( (array) $pages as $p ) {
+	 	
+	 	$parent_id = intval( $p->post_parent );
+	 	$children[ $parent_id ][] = $p;
+	 }
+	 
+	 $page_list = array();
+	 _page_traverse( $page_id, $children, $page_list );
+	 
+	return $page_list;
+}
+
+/**
+ * function to traverse and return all the nested children of a root page.
+ * $children contains parent-chilren relations
+ * 
+ */
+function _page_traverse( $page_id, &$children, &$page_list ){ 
+	
+	if ( isset( $children[ $page_id ] ) ){
+		
+		foreach( (array)$children[ $page_id ] as $child ) {
+			
+			$page_list[] = $child; 
+			_page_traverse( $child->ID, $children, $page_list ); 
 		}
 	}
-	return $page_list;
 }
 
 /**
