소스 검색

optimization to call `$this->getOption('code')` only once

Christian Raue 14 년 전
부모
커밋
451616fa65
1개의 변경된 파일6개의 추가작업 그리고 4개의 파일을 삭제
  1. 6 4
      Admin/BaseFieldDescription.php

+ 6 - 4
Admin/BaseFieldDescription.php

@@ -318,16 +318,18 @@ abstract class BaseFieldDescription implements FieldDescriptionInterface
      */
     public function getFieldValue($object, $fieldName)
     {
-        if (is_callable($this->getOption('code'))) {
-            return call_user_func($this->getOption('code'), $object);
+        $code = $this->getOption('code');
+
+        if (is_callable($code)) {
+            return call_user_func($code, $object);
         }
 
         $camelizedFieldName = self::camelize($fieldName);
 
         $getters = array();
         // prefer method name given in the code option
-        if ($this->getOption('code')) {
-            $getters[] = $this->getOption('code');
+        if ($code) {
+            $getters[] = $code;
         }
         $getters[] = 'get' . $camelizedFieldName;
         $getters[] = 'is' . $camelizedFieldName;