Permalink
Browse files

MDL-27120 backup: replace sequential scan search with hash-based lookup.

  • Loading branch information...
1 parent 4f7f2a8 commit 9e4b9a00cc1b1ceb8ca5314b9c9cac71e2a3944d Ashley Holman committed with rajeshtaneja Apr 7, 2011
Showing with 10 additions and 12 deletions.
  1. +10 −12 backup/util/plan/base_plan.class.php
@@ -61,7 +61,12 @@ public function add_task($task) {
// 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 @@ public function get_settings() {
*/
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;
}

0 comments on commit 9e4b9a0

Please sign in to comment.