From c1aeda6d016330abbc9bf62f2cfbce22c66714f0 Mon Sep 17 00:00:00 2001 From: Cedric Ziel <cedric@cedric-ziel.com> Date: Wed, 15 Mar 2017 10:36:14 +0100 Subject: [PATCH] [TASK] Use direct array assignments instead of array_push Direct assignments are usually 2x faster and often more readable when pushing one value only. Releases: master Fixes: #80283 Change-Id: I16fc1938f74550d1a3d9f9c0cbafe85dc2ff1c5b Reviewed-on: https://review.typo3.org/52049 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Classes/Controller/FormInlineAjaxController.php | 9 +++------ typo3/sysext/core/Classes/Charset/CharsetConverter.php | 4 ++-- typo3/sysext/core/Classes/Html/HtmlParser.php | 4 ++-- typo3/sysext/core/Classes/Service/AbstractService.php | 2 +- .../core/Classes/Service/DependencyOrderingService.php | 2 +- typo3/sysext/core/Classes/TimeTracker/TimeTracker.php | 4 ++-- typo3/sysext/core/Classes/Utility/RootlineUtility.php | 2 +- typo3/sysext/extbase/Classes/Error/Result.php | 2 +- typo3/sysext/extbase/Classes/Scheduler/FieldProvider.php | 4 ++-- typo3/sysext/extbase/Classes/Scheduler/Task.php | 2 +- .../Configuration/TCA/Overrides/fe_users.php | 2 +- .../Classes/Utility/DependencyUtility.php | 2 +- .../Classes/ContentObject/LoadRegisterContentObject.php | 2 +- .../Classes/Controller/TranslationStatusController.php | 2 +- .../recordlist/Classes/LinkHandler/PageLinkHandler.php | 2 +- .../recordlist/Classes/RecordList/DatabaseRecordList.php | 8 ++++---- 16 files changed, 25 insertions(+), 28 deletions(-) diff --git a/typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php b/typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php index 2a2884e3e0ee..72204045b520 100644 --- a/typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php +++ b/typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php @@ -401,12 +401,9 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController } // Tell JS to add new HTML of one or multiple (localize all) records to DOM if (!empty($jsonArray['data'])) { - array_push( - $jsonArray['scriptCall'], - 'inline.domAddNewRecord(\'bottom\', ' . GeneralUtility::quoteJSvalue($nameObject . '_records') - . ', ' . GeneralUtility::quoteJSvalue($nameObjectForeignTable) - . ', json.data);' - ); + $jsonArray['scriptCall'][] = 'inline.domAddNewRecord(\'bottom\', ' . GeneralUtility::quoteJSvalue($nameObject . '_records') + . ', ' . GeneralUtility::quoteJSvalue($nameObjectForeignTable) + . ', json.data);'; } } diff --git a/typo3/sysext/core/Classes/Charset/CharsetConverter.php b/typo3/sysext/core/Classes/Charset/CharsetConverter.php index 7c633d078346..01c4e9c23eed 100644 --- a/typo3/sysext/core/Classes/Charset/CharsetConverter.php +++ b/typo3/sysext/core/Classes/Charset/CharsetConverter.php @@ -979,7 +979,7 @@ class CharsetConverter implements SingletonInterface } } elseif (!isset($mark['U+' . $code_value])) { // remove mark - array_push($code_decomp, $code_value); + $code_decomp[] = $code_value; } } if (!empty($code_decomp) || isset($omit[$from])) { @@ -999,7 +999,7 @@ class CharsetConverter implements SingletonInterface continue 2; } else { // Skip decompositions containing non-ASCII chars - array_push($code_decomp, chr($ord)); + $code_decomp[] = chr($ord); } } $ascii[$this->UnumberToChar(hexdec($from))] = implode('', $code_decomp); diff --git a/typo3/sysext/core/Classes/Html/HtmlParser.php b/typo3/sysext/core/Classes/Html/HtmlParser.php index 3402cf99a982..e3cccecab912 100644 --- a/typo3/sysext/core/Classes/Html/HtmlParser.php +++ b/typo3/sysext/core/Classes/Html/HtmlParser.php @@ -611,9 +611,9 @@ class HtmlParser } } } else { - array_push($tagRegister[$tagName], $c); + $tagRegister[$tagName][] = $c; if ($tags[$tagName]['nesting'] === 'global') { - array_push($tagStack, $tagName); + $tagStack[] = $tagName; } } } diff --git a/typo3/sysext/core/Classes/Service/AbstractService.php b/typo3/sysext/core/Classes/Service/AbstractService.php index a58b4740cba4..1ccd22548b4f 100644 --- a/typo3/sysext/core/Classes/Service/AbstractService.php +++ b/typo3/sysext/core/Classes/Service/AbstractService.php @@ -164,7 +164,7 @@ abstract class AbstractService */ public function errorPush($errNum = T3_ERR_SV_GENERAL, $errMsg = 'Unspecified error occurred') { - array_push($this->error, ['nr' => $errNum, 'msg' => $errMsg]); + $this->error[] = ['nr' => $errNum, 'msg' => $errMsg]; /** @var \TYPO3\CMS\Core\TimeTracker\TimeTracker $timeTracker */ $timeTracker = GeneralUtility::makeInstance(TimeTracker::class); $timeTracker->setTSlogMessage($errMsg, 2); diff --git a/typo3/sysext/core/Classes/Service/DependencyOrderingService.php b/typo3/sysext/core/Classes/Service/DependencyOrderingService.php index 62798e3c0f13..df5de9c8ab73 100644 --- a/typo3/sysext/core/Classes/Service/DependencyOrderingService.php +++ b/typo3/sysext/core/Classes/Service/DependencyOrderingService.php @@ -157,7 +157,7 @@ class DependencyOrderingService } unset($rootIds[$currentId]); - array_push($sortedIds, $currentId); + $sortedIds[] = $currentId; // Process the dependencies of the current node foreach (array_filter($dependencyGraph[$currentId]) as $dependingId => $_) { diff --git a/typo3/sysext/core/Classes/TimeTracker/TimeTracker.php b/typo3/sysext/core/Classes/TimeTracker/TimeTracker.php index 4b56019336f4..14bf30ce3e3c 100644 --- a/typo3/sysext/core/Classes/TimeTracker/TimeTracker.php +++ b/typo3/sysext/core/Classes/TimeTracker/TimeTracker.php @@ -163,8 +163,8 @@ class TimeTracker implements SingletonInterface if (!$this->isEnabled) { return; } - array_push($this->tsStack[$this->tsStackPointer], $tslabel); - array_push($this->currentHashPointer, 'timetracker_' . $this->uniqueCounter++); + $this->tsStack[$this->tsStackPointer][] = $tslabel; + $this->currentHashPointer[] = 'timetracker_' . $this->uniqueCounter++; $this->tsStackLevel++; $this->tsStackLevelMax[] = $this->tsStackLevel; // setTSlog diff --git a/typo3/sysext/core/Classes/Utility/RootlineUtility.php b/typo3/sysext/core/Classes/Utility/RootlineUtility.php index 1c27eaabe995..a182cb506620 100644 --- a/typo3/sysext/core/Classes/Utility/RootlineUtility.php +++ b/typo3/sysext/core/Classes/Utility/RootlineUtility.php @@ -416,7 +416,7 @@ class RootlineUtility } else { $rootline = []; } - array_push($rootline, $page); + $rootline[] = $page; krsort($rootline); static::$cache->set($this->cacheIdentifier, $rootline, $cacheTags); static::$localCache[$this->cacheIdentifier] = $rootline; diff --git a/typo3/sysext/extbase/Classes/Error/Result.php b/typo3/sysext/extbase/Classes/Error/Result.php index df5ee68a109a..7a3d8d1a1098 100644 --- a/typo3/sysext/extbase/Classes/Error/Result.php +++ b/typo3/sysext/extbase/Classes/Error/Result.php @@ -422,7 +422,7 @@ class Result $result[implode('.', $level)] = $this->$propertyName; } foreach ($this->propertyResults as $subPropertyName => $subResult) { - array_push($level, $subPropertyName); + $level[] = $subPropertyName; $subResult->flattenTree($propertyName, $result, $level); array_pop($level); } diff --git a/typo3/sysext/extbase/Classes/Scheduler/FieldProvider.php b/typo3/sysext/extbase/Classes/Scheduler/FieldProvider.php index 50689c08ab56..b65b8d11819b 100644 --- a/typo3/sysext/extbase/Classes/Scheduler/FieldProvider.php +++ b/typo3/sysext/extbase/Classes/Scheduler/FieldProvider.php @@ -302,9 +302,9 @@ class FieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInter ]; foreach ($options as $optionValue => $optionLabel) { $selected = $optionValue === $selectedOptionValue ? ' selected="selected"' : ''; - array_push($html, '<option title="test" value="' . htmlspecialchars($optionValue) . '"' . $selected . '>' . htmlspecialchars($optionLabel) . '</option>'); + $html[] = '<option title="test" value="' . htmlspecialchars($optionValue) . '"' . $selected . '>' . htmlspecialchars($optionLabel) . '</option>'; } - array_push($html, '</select>'); + $html[] = '</select>'; return implode(LF, $html); } diff --git a/typo3/sysext/extbase/Classes/Scheduler/Task.php b/typo3/sysext/extbase/Classes/Scheduler/Task.php index bd81c92aa9c6..aeb97a4b646e 100644 --- a/typo3/sysext/extbase/Classes/Scheduler/Task.php +++ b/typo3/sysext/extbase/Classes/Scheduler/Task.php @@ -174,7 +174,7 @@ class Task extends \TYPO3\CMS\Scheduler\Task\AbstractTask $arguments = []; foreach ($this->arguments as $argumentName => $argumentValue) { if ($argumentValue != $this->defaults[$argumentName]) { - array_push($arguments, $argumentName . '=' . $argumentValue); + $arguments[] = $argumentName . '=' . $argumentValue; } } $label .= ' ' . implode(', ', $arguments); diff --git a/typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/Overrides/fe_users.php b/typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/Overrides/fe_users.php index a2257c78076a..48a040345990 100644 --- a/typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/Overrides/fe_users.php +++ b/typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/Overrides/fe_users.php @@ -3,5 +3,5 @@ defined('TYPO3_MODE') or die(); if (is_array($GLOBALS['TCA']['fe_users']['columns']['tx_extbase_type'])) { $GLOBALS['TCA']['fe_users']['types']['Tx_BlogExample_Domain_Model_Administrator'] = $GLOBALS['TCA']['fe_users']['types']['0']; - array_push($GLOBALS['TCA']['fe_users']['columns']['tx_extbase_type']['config']['items'], ['LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:fe_users.tx_extbase_type.Tx_BlogExample_Domain_Model_Administrator', 'Tx_BlogExample_Domain_Model_Administrator']); + $GLOBALS['TCA']['fe_users']['columns']['tx_extbase_type']['config']['items'][] = ['LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:fe_users.tx_extbase_type.Tx_BlogExample_Domain_Model_Administrator', 'Tx_BlogExample_Domain_Model_Administrator']; } diff --git a/typo3/sysext/extensionmanager/Classes/Utility/DependencyUtility.php b/typo3/sysext/extensionmanager/Classes/Utility/DependencyUtility.php index 265629fc69f6..77e6bfd848a9 100644 --- a/typo3/sysext/extensionmanager/Classes/Utility/DependencyUtility.php +++ b/typo3/sysext/extensionmanager/Classes/Utility/DependencyUtility.php @@ -592,7 +592,7 @@ class DependencyUtility implements \TYPO3\CMS\Core\SingletonInterface if ($dependency->getIdentifier() === 'typo3') { try { if ($this->checkTypo3Dependency($dependency)) { - array_push($suitableExtensions, $extension); + $suitableExtensions[] = $extension; } } catch (Exception\UnresolvedTypo3DependencyException $e) { } diff --git a/typo3/sysext/frontend/Classes/ContentObject/LoadRegisterContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/LoadRegisterContentObject.php index 9892376b82dd..812fe4489bb0 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/LoadRegisterContentObject.php +++ b/typo3/sysext/frontend/Classes/ContentObject/LoadRegisterContentObject.php @@ -28,7 +28,7 @@ class LoadRegisterContentObject extends AbstractContentObject */ public function render($conf = []) { - array_push($GLOBALS['TSFE']->registerStack, $GLOBALS['TSFE']->register); + $GLOBALS['TSFE']->registerStack[] = $GLOBALS['TSFE']->register; if (is_array($conf)) { $isExecuted = []; foreach ($conf as $theKey => $theValue) { diff --git a/typo3/sysext/frontend/Classes/Controller/TranslationStatusController.php b/typo3/sysext/frontend/Classes/Controller/TranslationStatusController.php index 05154cf9891f..8823cb369f07 100644 --- a/typo3/sysext/frontend/Classes/Controller/TranslationStatusController.php +++ b/typo3/sysext/frontend/Classes/Controller/TranslationStatusController.php @@ -303,7 +303,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc if (!empty($newOL_js[$langRow['uid']])) { $onClickArray = explode('?', $onClick, 2); $lastElement = array_pop($onClickArray); - array_push($onClickArray, '\'' . $newOL_js[$langRow['uid']] . ' + \'&' . $lastElement); + $onClickArray[] = '\'' . $newOL_js[$langRow['uid']] . ' + \'&' . $lastElement; $onClick = implode('?', $onClickArray); } $newButton = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onClick) diff --git a/typo3/sysext/recordlist/Classes/LinkHandler/PageLinkHandler.php b/typo3/sysext/recordlist/Classes/LinkHandler/PageLinkHandler.php index b9f723f586da..4c6358f6b337 100644 --- a/typo3/sysext/recordlist/Classes/LinkHandler/PageLinkHandler.php +++ b/typo3/sysext/recordlist/Classes/LinkHandler/PageLinkHandler.php @@ -306,7 +306,7 @@ class PageLinkHandler extends AbstractLinkHandler implements LinkHandlerInterfac { $configuration = $this->linkBrowser->getConfiguration(); if (!empty($configuration['pageIdSelector.']['enabled'])) { - array_push($this->linkAttributes, 'pageIdSelector'); + $this->linkAttributes[] = 'pageIdSelector'; $fieldDefinitions['pageIdSelector'] = ' <tr> <td> diff --git a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php index 0ab504d59fcd..2d0f7835d865 100644 --- a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php +++ b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php @@ -506,7 +506,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList $rowListArray = GeneralUtility::trimExplode(',', $rowList, true); // if no columns have been specified, show description (if configured) if (!empty($GLOBALS['TCA'][$table]['ctrl']['descriptionColumn']) && empty($rowListArray)) { - array_push($rowListArray, $GLOBALS['TCA'][$table]['ctrl']['descriptionColumn']); + $rowListArray[] = $GLOBALS['TCA'][$table]['ctrl']['descriptionColumn']; } $backendUser = $this->getBackendUserAuthentication(); $lang = $this->getLanguageService(); @@ -1126,7 +1126,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList $onClick = BackendUtility::editOnClick('', '', -1); $onClickArray = explode('?', $onClick, 2); $lastElement = array_pop($onClickArray); - array_push($onClickArray, $params . '&' . $lastElement); + $onClickArray[] = $params . '&' . $lastElement; $onClick = implode('?', $onClickArray); $cells['edit'] = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($lang->getLL('clip_editMarked')) . '">' @@ -1215,7 +1215,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList $onClick = BackendUtility::editOnClick('', '', -1); $onClickArray = explode('?', $onClick, 2); $lastElement = array_pop($onClickArray); - array_push($onClickArray, $params . '&' . $lastElement); + $onClickArray[] = $params . '&' . $lastElement; $onClick = implode('?', $onClickArray); $icon .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($lang->getLL('editShownColumns')) . '">' @@ -1261,7 +1261,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList $onClick = BackendUtility::editOnClick('', '', -1); $onClickArray = explode('?', $onClick, 2); $lastElement = array_pop($onClickArray); - array_push($onClickArray, $params . '&' . $lastElement); + $onClickArray[] = $params . '&' . $lastElement; $onClick = implode('?', $onClickArray); $iTitle = sprintf($lang->getLL('editThisColumn'), $sortLabel); $theData[$fCol] .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) -- GitLab