Unverified Commit cbcdb8b2 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3164210 by jungle, sylus, Akhildev.cs, dww: Refactor array_merge()...

Issue #3164210 by jungle, sylus, Akhildev.cs, dww: Refactor array_merge() usage in loops as possible for performance
parent 0c8a680e
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -72,10 +72,7 @@ public function getSortedProviders() {
      krsort($this->providerOrders);

      // Merge nested providers from $this->providers into $this->sortedProviders.
      $this->sortedProviders = [];
      foreach ($this->providerOrders as $providers) {
        $this->sortedProviders = array_merge($this->sortedProviders, $providers);
      }
      $this->sortedProviders = array_merge([], ...$this->providerOrders);
    }

    return $this->sortedProviders;
+1 −4
Original line number Diff line number Diff line
@@ -107,10 +107,7 @@ protected function getSortedBuilders() {
      // Sort the builders according to priority.
      krsort($this->builders);
      // Merge nested builders from $this->builders into $this->sortedBuilders.
      $this->sortedBuilders = [];
      foreach ($this->builders as $builders) {
        $this->sortedBuilders = array_merge($this->sortedBuilders, $builders);
      }
      $this->sortedBuilders = array_merge([], ...$this->builders);
    }
    return $this->sortedBuilders;
  }
+2 −2
Original line number Diff line number Diff line
@@ -264,9 +264,9 @@ public function findConfigEntityDependencies($type, array $names, ConfigDependen
    }
    $dependencies = [];
    foreach ($names as $name) {
      $dependencies = array_merge($dependencies, $dependency_manager->getDependentEntities($type, $name));
      $dependencies[] = $dependency_manager->getDependentEntities($type, $name);
    }
    return $dependencies;
    return array_merge([], ...$dependencies);
  }

  /**
+5 −3
Original line number Diff line number Diff line
@@ -58,8 +58,9 @@ public function checkConfigSchema(TypedConfigManagerInterface $typed_config, $co
    $this->schema = $typed_config->createFromNameAndData($config_name, $config_data);
    $errors = [];
    foreach ($config_data as $key => $value) {
      $errors = array_merge($errors, $this->checkValue($key, $value));
      $errors[] = $this->checkValue($key, $value);
    }
    $errors = array_merge([], ...$errors);
    if (empty($errors)) {
      return TRUE;
    }
@@ -130,11 +131,12 @@ protected function checkValue($key, $value) {
      if (!is_array($value)) {
        $value = (array) $value;
      }
      $nested_errors = [];
      // Recurse into any nested keys.
      foreach ($value as $nested_value_key => $nested_value) {
        $errors = array_merge($errors, $this->checkValue($key . '.' . $nested_value_key, $nested_value));
        $nested_errors[] = $this->checkValue($key . '.' . $nested_value_key, $nested_value);
      }
      return $errors;
      return array_merge($errors, ...$nested_errors);
    }
    // No errors found.
    return [];
+5 −3
Original line number Diff line number Diff line
@@ -340,12 +340,14 @@ public function fieldAccess($operation, FieldDefinitionInterface $field_definiti
    $default = $default->andIf($entity_default);

    // Invoke hook and collect grants/denies for field access from other
    // modules. Our default access flag is masked under the ':default' key.
    $grants = [':default' => $default];
    // modules.
    $grants = [];
    $hook_implementations = $this->moduleHandler()->getImplementations('entity_field_access');
    foreach ($hook_implementations as $module) {
      $grants = array_merge($grants, [$module => $this->moduleHandler()->invoke($module, 'entity_field_access', [$operation, $field_definition, $account, $items])]);
      $grants[] = [$module => $this->moduleHandler()->invoke($module, 'entity_field_access', [$operation, $field_definition, $account, $items])];
    }
    // Our default access flag is masked under the ':default' key.
    $grants = array_merge([':default' => $default], ...$grants);

    // Also allow modules to alter the returned grants/denies.
    $context = [
Loading