Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294618

Refactor array_merge() usage in loops as possible for performance

$
0
0

Problem/Motivation

[EA] 'array_merge(...)' is used in a loop and is a resources greedy construction.

See https://github.com/kalessil/phpinspectionsea/blob/master/docs/performanc...

Steps to reproduce

Proposed resolution

Example :


  // @see core/modules/views/src/Plugin/views/query/Sql.php

   public function getWhereArgs() {
-    $args = [];
-    foreach ($this->where as $where) {
-      $args = array_merge($args, $where['args']);
-    }
-    foreach ($this->having as $having) {
-      $args = array_merge($args, $having['args']);
-    }
-    return $args;
+    return array_merge([], ...array_column($this->where, 'args'), ...array_column($this->having, 'args'));
   }

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 294618

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>