Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 4528)
+++ wp-includes/post.php	(working copy)
@@ -1025,20 +1025,29 @@
 	return $result;
 }
 
+function _get_page_uri_hierarchy($posts, $parent = 0, $parent_uri = '') {
+	$result = array ( );
+	if ($posts) { foreach ($posts as $post) {
+		if ($post->post_parent == $parent) {
+
+			$current_uri = urldecode($post->post_name);
+			if($parent_uri != '')
+				$current_uri = $parent_uri . '/'. $current_uri;
+			$result[$post->ID] = $current_uri;
+			$children = _get_page_uri_hierarchy($posts, $post->ID, $current_uri);
+			$result += $children; //append $children to $result
+		}
+	} }
+	return $result;
+}
+
 function get_page_uri($page_id) {
-	$page = get_page($page_id);
-	$uri = urldecode($page->post_name);
+	global $uris, $wpdb;
 
-	// A page cannot be it's own parent.
-	if ( $page->post_parent == $page->ID )
-		return $uri;
+	if(!is_array($uris))
+		$uris = _get_page_uri_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' OR post_type='attachment'"));
 
-	while ($page->post_parent != 0) {
-		$page = get_page($page->post_parent);
-		$uri = urldecode($page->post_name) . "/" . $uri;
-	}
-
-	return $uri;
+	return $uris[$page_id];
 }
 
 function &get_pages($args = '') {
