Skip to content

Commit 424821e

Browse files
committed
Use isset over in_array for better performance
1 parent b6aca59 commit 424821e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/internal/Magento/Framework/Data/Collection/AbstractDb.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ abstract class AbstractDb extends \Magento\Framework\Data\Collection
9999
*/
100100
protected $extensionAttributesJoinProcessor;
101101

102-
/** @see https://en.wikipedia.org/wiki/List_of_SQL_reserved_words */
103-
private const SQL_RESERVED_WORDS = [
102+
/**
103+
* @see https://en.wikipedia.org/wiki/List_of_SQL_reserved_words
104+
* @var array
105+
*/
106+
private array $sqlReservedWords = [
104107
'ABORT', 'ABORTSESSION', 'ABS', 'ABSENT', 'ABSOLUTE', 'ACCESS',
105108
'ACCESS_LOCK', 'ACCESSIBLE', 'ACCOUNT', 'ACOS', 'ACOSH', 'ACTION',
106109
'ADD', 'ADD_MONTHS', 'ADMIN', 'AFTER', 'AGGREGATE', 'ALIAS', 'ALL',
@@ -278,6 +281,7 @@ public function __construct(
278281
$this->setConnection($connection);
279282
}
280283
$this->_logger = $logger;
284+
$this->sqlReservedWords = array_flip($this->sqlReservedWords);
281285
}
282286

283287
/**
@@ -666,7 +670,7 @@ protected function _renderOrders()
666670
{
667671
if (!$this->_isOrdersRendered) {
668672
foreach ($this->_orders as $field => $direction) {
669-
if (in_array(strtoupper($field), self::SQL_RESERVED_WORDS)) {
673+
if (isset($this->sqlReservedWords[strtoupper($field)])) {
670674
$field = "`$field`";
671675
}
672676
$this->_select->order(new \Zend_Db_Expr($field . ' ' . $direction));

0 commit comments

Comments
 (0)