From 74256eafcbb0b9fd3038d4355326ef946e9c240c Mon Sep 17 00:00:00 2001
From: Remon Georgy <remon.sherin@gmail.com>
Date: Fri, 11 Mar 2011 17:14:25 +0200
Subject: [PATCH] Issue #1089040 by Remon: Cache rdf_get_namespaces using drupal_static.

---
 modules/rdf/rdf.module |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/modules/rdf/rdf.module b/modules/rdf/rdf.module
index ebecd42..b213ebb 100644
--- a/modules/rdf/rdf.module
+++ b/modules/rdf/rdf.module
@@ -95,23 +95,26 @@ function rdf_rdf_namespaces() {
  * hook_rdf_namespaces().
  */
 function rdf_get_namespaces() {
-  $rdf_namespaces = module_invoke_all('rdf_namespaces');
-  // module_invoke_all() uses array_merge_recursive() which might return nested
-  // arrays if several modules redefine the same prefix multiple times. We need
-  // to ensure the array of namespaces is flat and only contains strings as
-  // URIs.
-  foreach ($rdf_namespaces as $prefix => $uri) {
-    if (is_array($uri)) {
-      if (count(array_unique($uri)) == 1) {
-        // All namespaces declared for this prefix are the same, merge them all
-        // into a single namespace.
-        $rdf_namespaces[$prefix] = $uri[0];
-      }
-      else {
-        // There are conflicting namespaces for this prefix, do not include
-        // duplicates in order to avoid asserting any inaccurate RDF
-        // statements.
-        unset($rdf_namespaces[$prefix]);
+  $rdf_namespaces = &drupal_static(__FUNCTION__);
+  if (!isset($rdf_namespaces)) {
+    $rdf_namespaces = module_invoke_all('rdf_namespaces');
+    // module_invoke_all() uses array_merge_recursive() which might return nested
+    // arrays if several modules redefine the same prefix multiple times. We need
+    // to ensure the array of namespaces is flat and only contains strings as
+    // URIs.
+    foreach ($rdf_namespaces as $prefix => $uri) {
+      if (is_array($uri)) {
+        if (count(array_unique($uri)) == 1) {
+          // All namespaces declared for this prefix are the same, merge them all
+          // into a single namespace.
+          $rdf_namespaces[$prefix] = $uri[0];
+        }
+        else {
+          // There are conflicting namespaces for this prefix, do not include
+          // duplicates in order to avoid asserting any inaccurate RDF
+          // statements.
+          unset($rdf_namespaces[$prefix]);
+        }
       }
     }
   }
-- 
1.7.1

