Browse Source

Merge pull request #9367 from cakephp/fewer-allocations

Do fewer allocations for simple default values.
José Lorenzo Rodríguez 9 years ago
parent
commit
8314c2ff83

+ 2 - 4
src/Auth/FallbackPasswordHasher.php

@@ -49,10 +49,8 @@ class FallbackPasswordHasher extends AbstractPasswordHasher
     {
         parent::__construct($config);
         foreach ($this->_config['hashers'] as $key => $hasher) {
-            if (!is_string($hasher)) {
-                $hasher += [
-                    'className' => $key,
-                ];
+            if (is_array($hasher) && !isset($hasher['className'])) {
+                $hasher['className'] = $key;
             }
             $this->_hashers[] = PasswordHasherFactory::build($hasher);
         }

+ 5 - 3
src/Controller/Component/FlashComponent.php

@@ -88,12 +88,14 @@ class FlashComponent extends Component
         $options += $this->config();
 
         if ($message instanceof Exception) {
-            $options['params'] += ['code' => $message->getCode()];
+            if (!isset($options['params']['code'])) {
+                $options['params']['code'] = $message->getCode();
+            }
             $message = $message->getMessage();
         }
 
-        if (isset($options['escape'])) {
-            $options['params'] += ['escape' => $options['escape']];
+        if (isset($options['escape']) && !isset($options['params']['escape'])) {
+            $options['params']['escape'] = $options['escape'];
         }
 
         list($plugin, $element) = pluginSplit($options['element']);

+ 2 - 2
src/Mailer/Email.php

@@ -1390,8 +1390,8 @@ class Email implements JsonSerializable, Serializable
     {
         $class = __CLASS__;
 
-        if (is_array($transportConfig)) {
-            $transportConfig += ['transport' => 'default'];
+        if (is_array($transportConfig) && !isset($transportConfig['transport'])) {
+            $transportConfig['transport'] = 'default';
         }
         $instance = new $class($transportConfig);
         if ($to !== null) {

+ 3 - 1
src/ORM/Association/BelongsToMany.php

@@ -375,7 +375,9 @@ class BelongsToMany extends Association
         if (empty($options['negateMatch'])) {
             return;
         }
-        $options += ['conditions' => []];
+        if (!isset($options['conditions'])) {
+            $options['conditions'] = [];
+        }
         $junction = $this->junction();
         $belongsTo = $junction->association($this->source()->alias());
         $conds = $belongsTo->_joinCondition(['foreignKey' => $belongsTo->foreignKey()]);

+ 3 - 1
src/ORM/Association/SelectableAssociationTrait.php

@@ -85,7 +85,9 @@ trait SelectableAssociationTrait
 
         $finder = isset($options['finder']) ? $options['finder'] : $this->finder();
         list($finder, $opts) = $this->_extractFinder($finder);
-        $options += ['fields' => []];
+        if (!isset($options['fields'])) {
+            $options['fields'] = [];
+        }
 
         $fetchQuery = $this
             ->find($finder, $opts)

+ 3 - 1
src/ORM/EagerLoader.php

@@ -200,12 +200,14 @@ class EagerLoader
         if ($assoc === null) {
             return $this->_matching->contain();
         }
+        if (!isset($options['joinType'])) {
+            $options['joinType'] = 'INNER';
+        }
 
         $assocs = explode('.', $assoc);
         $last = array_pop($assocs);
         $containments = [];
         $pointer =& $containments;
-        $options += ['joinType' => 'INNER'];
         $opts = ['matching' => true] + $options;
         unset($opts['negateMatch']);
 

+ 3 - 1
src/ORM/Marshaller.php

@@ -79,7 +79,9 @@ class Marshaller
         }
 
         // Map associations
-        $options += ['associated' => []];
+        if (!isset($options['associated'])) {
+            $options['associated'] = [];
+        }
         $include = $this->_normalizeAssociations($options['associated']);
         foreach ($include as $key => $nested) {
             if (is_int($key) && is_scalar($nested)) {

+ 2 - 2
src/Routing/RouteBuilder.php

@@ -454,8 +454,8 @@ class RouteBuilder
      */
     public function connect($route, array $defaults = [], array $options = [])
     {
-        if (empty($options['action'])) {
-            $defaults += ['action' => 'index'];
+        if (!isset($options['action']) && !isset($defaults['action'])) {
+            $defaults['action'] = 'index';
         }
 
         if (empty($options['_ext'])) {

+ 3 - 1
src/Routing/Router.php

@@ -223,10 +223,12 @@ class Router
      */
     public static function redirect($route, $url, $options = [])
     {
-        $options += ['routeClass' => 'Cake\Routing\Route\RedirectRoute'];
         if (is_string($url)) {
             $url = ['redirect' => $url];
         }
+        if (!isset($options['routeClass'])) {
+            $options['routeClass'] = 'Cake\Routing\Route\RedirectRoute';
+        }
         static::connect($route, $url, $options);
     }