MDL-27120 backup: replace sequential scan search with hash-based lookup.
authorAshley Holman <ashley@netspot.com.au>
Thu, 7 Apr 2011 04:46:07 +0000 (14:16 +0930)
committerRajesh Taneja <rajesh@moodle.com>
Tue, 29 May 2012 06:44:06 +0000 (14:44 +0800)
backup/util/plan/base_plan.class.php

index 3ed176b..24becc6 100644 (file)
@@ -61,7 +61,12 @@ abstract class base_plan implements checksumable, executable {
         // Append task settings to plan array, if not present, for comodity
         foreach ($task->get_settings() as $key => $setting) {
             if (!in_array($setting, $this->settings)) {
         // Append task settings to plan array, if not present, for comodity
         foreach ($task->get_settings() as $key => $setting) {
             if (!in_array($setting, $this->settings)) {
-                $this->settings[] = $setting;
+                $name = $setting->get_name();
+                if(!isset($this->settings[$name])) {
+                    $this->settings[$name] = $setting;
+                } else {
+                    throw new base_plan_exception('multiple_settings_by_name_found', $name);
+                }
             }
         }
     }
             }
         }
     }
@@ -91,17 +96,10 @@ abstract class base_plan implements checksumable, executable {
      */
     public function get_setting($name) {
         $result = null;
      */
     public function get_setting($name) {
         $result = null;
-        foreach ($this->settings as $key => $setting) {
-            if ($setting->get_name() == $name) {
-                if ($result != null) {
-                    throw new base_plan_exception('multiple_settings_by_name_found', $name);
-                } else {
-                    $result = $setting;
-                }
-            }
-        }
-        if (!$result) {
-            throw new base_plan_exception('setting_by_name_not_found', $name);
+        if(isset($this->settings[$name])) {
+           $result = $this->settings[$name];
+        } else {
+           throw new base_plan_exception('setting_by_name_not_found', $name);
         }
         return $result;
     }
         }
         return $result;
     }