Browse Source

Improve speed for options validation.

Daniele Alessandri 14 years ago
parent
commit
17f51420ce
2 changed files with 14 additions and 5 deletions
  1. 10 4
      lib/Predis/Options/CustomOption.php
  2. 4 1
      lib/Predis/Options/Option.php

+ 10 - 4
lib/Predis/Options/CustomOption.php

@@ -26,17 +26,23 @@ class CustomOption implements IOption {
             if ($this->_validate === null) {
                 return $value;
             }
-            return call_user_func($this->_validate, $value);
+            $validator = $this->_validate;
+            return $validator($value);
         }
     }
 
     public function getDefault() {
-        if ($this->_default !== null) {
-            return call_user_func($this->_default);
+        if (!isset($this->_default)) {
+            return;
         }
+        $default = $this->_default;
+        return $default();
     }
 
     public function __invoke($value) {
-        return isset($value) ? $this->validate($value) : $this->getDefault();
+        if (isset($value)) {
+            return $this->validate($value);
+        }
+        return $this->getDefault();
     }
 }

+ 4 - 1
lib/Predis/Options/Option.php

@@ -12,6 +12,9 @@ class Option implements IOption {
     }
 
     public function __invoke($value) {
-        return isset($value) ? $this->validate($value) : $this->getDefault();
+        if (isset($value)) {
+            return $this->validate($value);
+        }
+        return $this->getDefault();
     }
 }