From f213bbd77a0ec89e8ddf223d6cd6db9aa1bee37f Mon Sep 17 00:00:00 2001 From: Ashley Holman Date: Thu, 7 Apr 2011 14:16:07 +0930 Subject: [PATCH] MDL-27120 backup: replace sequential scan search with hash-based lookup. --- backup/util/plan/base_plan.class.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/backup/util/plan/base_plan.class.php b/backup/util/plan/base_plan.class.php index 3ed176b0bbf..24becc6969b 100644 --- a/backup/util/plan/base_plan.class.php +++ b/backup/util/plan/base_plan.class.php @@ -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)) { - $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; - 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; } -- 2.43.0