Skip to content

Commit

Permalink
CO: array_push calls behaving as $array[] works faster than invoking …
Browse files Browse the repository at this point in the history
…functions in PHP
  • Loading branch information
lfluvisotto committed Jun 23, 2018
1 parent f9f8b81 commit 5d2f2f9
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 68 deletions.
2 changes: 1 addition & 1 deletion classes/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public static function test_files($full = false)
foreach (ConfigurationTest::$test_files as $file) {
if (!file_exists(rtrim(_PS_ROOT_DIR_, DIRECTORY_SEPARATOR).str_replace('/', DIRECTORY_SEPARATOR, $file))) {
if ($full) {
array_push($return, $file);
$return[] = $file;
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ public static function deferInlineScripts($output)
if ($version != _PS_JQUERY_VERSION_) {
Context::getContext()->controller->addJquery($version, null, $minifier);
}
array_push(Media::$inline_script_src, $src);
Media::$inline_script_src[] = $src;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3749,7 +3749,7 @@ public function storeContactImportOne($info, $shop_is_feature_active, $regenerat
if (isset($store->hours) && is_array($store->hours)) {
$newHours = array();
foreach ($store->hours as $hour) {
array_push($newHours, array($hour));
$newHours[] = array($hour);
}
$store->hours = json_encode($newHours);
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminModulesPositionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public function ajaxProcessGetHookableList()
$hookableList[$hook_name] = array();
}
if ($moduleInstance->isHookableOn($hook_name)) {
array_push($hookableList[$hook_name], str_replace('_', '-', $module));
$hookableList[$hook_name][] = str_replace('_', '-', $module);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminTranslationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2842,7 +2842,7 @@ public function copyMailFilesForAllLanguages()
$stack = array();
$folder = dirname($file['to']);
while (!is_dir($folder)) {
array_push($stack, $folder);
$stack[] = $folder;
$folder = dirname($folder);
}
while ($folder = array_pop($stack)) {
Expand Down
88 changes: 32 additions & 56 deletions controllers/front/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,34 +370,25 @@ protected function processChangeProductInCart()
}

if ($this->qty == 0) {
array_push(
$this->{$ErrorKey},
$this->trans(
'Null quantity.',
array(),
'Shop.Notifications.Error'
)
$this->{$ErrorKey}[] = $this->trans(
'Null quantity.',
array(),
'Shop.Notifications.Error'
);
} elseif (!$this->id_product) {
array_push(
$this->{$ErrorKey},
$this->trans(
'Product not found',
array(),
'Shop.Notifications.Error'
)
$this->{$ErrorKey}[] = $this->trans(
'Product not found',
array(),
'Shop.Notifications.Error'
);
}

$product = new Product($this->id_product, true, $this->context->language->id);
if (!$product->id || !$product->active || !$product->checkAccess($this->context->cart->id_customer)) {
array_push(
$this->{$ErrorKey},
$this->trans(
'This product (%product%) is no longer available.',
array('%product%' => $product->name),
'Shop.Notifications.Error'
)
$this->{$ErrorKey}[] = $this->trans(
'This product (%product%) is no longer available.',
array('%product%' => $product->name),
'Shop.Notifications.Error'
);
return;
}
Expand Down Expand Up @@ -434,13 +425,10 @@ protected function processChangeProductInCart()

// Check product quantity availability
if ('update' !== $mode && $this->shouldAvailabilityErrorBeRaised($product, $qty_to_check)) {
array_push(
$this->{$ErrorKey},
$this->trans(
'The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.',
array('%product%' => $product->name),
'Shop.Notifications.Error'
)
$this->{$ErrorKey}[] = $this->trans(
'The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.',
array('%product%' => $product->name),
'Shop.Notifications.Error'
);
}

Expand All @@ -461,13 +449,10 @@ protected function processChangeProductInCart()
// Check customizable fields

if (!$product->hasAllRequiredCustomizableFields() && !$this->customization_id) {
array_push(
$this->{$ErrorKey},
$this->trans(
'Please fill in all of the required fields, and then save your customizations.',
array(),
'Shop.Notifications.Error'
)
$this->{$ErrorKey}[] = $this->trans(
'Please fill in all of the required fields, and then save your customizations.',
array(),
'Shop.Notifications.Error'
);
}

Expand Down Expand Up @@ -499,32 +484,23 @@ protected function processChangeProductInCart()
$minimal_quantity = ($this->id_product_attribute)
? Attribute::getAttributeMinimalQty($this->id_product_attribute)
: $product->minimal_quantity;
array_push(
$this->{$ErrorKey},
$this->trans(
'You must add %quantity% minimum quantity',
array('%quantity%' => $minimal_quantity),
'Shop.Notifications.Error'
)
$this->{$ErrorKey}[] = $this->trans(
'You must add %quantity% minimum quantity',
array('%quantity%' => $minimal_quantity),
'Shop.Notifications.Error'
);
} elseif (!$update_quantity) {
array_push(
$this->errors,
$this->trans(
'You already have the maximum quantity available for this product.',
array(),
'Shop.Notifications.Error'
)
$this->errors[] = $this->trans(
'You already have the maximum quantity available for this product.',
array(),
'Shop.Notifications.Error'
);
} elseif ($this->shouldAvailabilityErrorBeRaised($product, $qty_to_check)) {
// check quantity after cart quantity update
array_push(
$this->{$ErrorKey},
$this->trans(
'The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.',
array('%product%' => $product->name),
'Shop.Notifications.Error'
)
$this->{$ErrorKey}[] = $this->trans(
'The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.',
array('%product%' => $product->name),
'Shop.Notifications.Error'
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/PrestaShopBundle/Service/TranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function listDomainTranslation($locale, $domain, $theme = null, $search =
if (empty($data['xliff']) && empty($data['database'])) {
array_unshift($domains['data'], $data);
} else {
array_push($domains['data'], $data);
$domains['data'][] = $data;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions tools/htmlpurifier/HTMLPurifier.standalone.php
Original file line number Diff line number Diff line change
Expand Up @@ -8119,7 +8119,7 @@ public function shift() {
* Pushes an element onto the front of the queue.
*/
public function push($x) {
array_push($this->input, $x);
$this->input[] = $x;
}

/**
Expand Down Expand Up @@ -9940,7 +9940,7 @@ public function toArray($t = null) {
* @return Original contents of new hole.
*/
public function next($t) {
if ($t !== null) array_push($this->front, $t);
if ($t !== null) $this->front[] = $t;
return empty($this->back) ? null : array_pop($this->back);
}

Expand All @@ -9963,7 +9963,7 @@ public function advance($t, $n) {
* @return Original contents of new hole.
*/
public function prev($t) {
if ($t !== null) array_push($this->back, $t);
if ($t !== null) $this->back[] = $t;
return empty($this->front) ? null : array_pop($this->front);
}

Expand All @@ -9989,15 +9989,15 @@ public function done() {
* @param Element to insert
*/
public function insertBefore($t) {
if ($t !== null) array_push($this->front, $t);
if ($t !== null) $this->front[] = $t;
}

/**
* Insert element after hole.
* @param Element to insert
*/
public function insertAfter($t) {
if ($t !== null) array_push($this->back, $t);
if ($t !== null) $this->back[] = $t;
}

/**
Expand Down Expand Up @@ -13178,7 +13178,7 @@ public function validate($aIP, $config, $context)
}

while (count($first) < 8) {
array_push($first, '0');
$first[] = '0';
}

array_splice($first, 8 - count($second), 8, $second);
Expand Down

0 comments on commit 5d2f2f9

Please sign in to comment.