[TASK] Replace GeneralUtility::inList() with isset() within loops 38/37138/3
authorJo Hasenau <info@cybercraft.de>
Mon, 23 Feb 2015 20:08:00 +0000 (21:08 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Sat, 16 May 2015 21:57:18 +0000 (23:57 +0200)
Rule of thumb should be to use GeneralUtility::inList() for
single checks of lists with unknown values only. Within loops
it will be faster to explode the list outside the loop, then flip
the array and finally use isset on the array keys within the loop.

Hardcoded lists might be replaced with arrays as well.

See the issue on forge for a description and some benchmarks.

This will not fully resolve the issue since there will be more
patches to come, since we should avoid monster patches to minimize
the risk of regressions.

Releases: master
Resolves: #55626
Change-Id: I5a0d8ea6f71a4f8fd39587c5ec3bfcb557d4c777
Reviewed-on: http://review.typo3.org/37138
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index d42dbe9..a3465cb 100644 (file)
@@ -3253,6 +3253,7 @@ class DataHandler {
                                                $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
                                                $tE = $this->getTableEntries($table, $TSConfig);
                                                // Traverse ALL fields of the selected record:
+                                               $setDefaultOnCopyArray = array_flip(GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['setToDefaultOnCopy']));
                                                foreach ($row as $field => $value) {
                                                        if (!in_array($field, $nonFields, TRUE)) {
                                                                // Get TCA configuration for the field:
@@ -3267,7 +3268,7 @@ class DataHandler {
                                                                } elseif (isset($copyAfterFields[$field])) {
                                                                        // Copy-after value if available:
                                                                        $value = $copyAfterFields[$field];
-                                                               } elseif ($GLOBALS['TCA'][$table]['ctrl']['setToDefaultOnCopy'] && GeneralUtility::inList($GLOBALS['TCA'][$table]['ctrl']['setToDefaultOnCopy'], $field)) {
+                                                               } elseif ($GLOBALS['TCA'][$table]['ctrl']['setToDefaultOnCopy'] && isset($setDefaultOnCopyArray[$field])) {
                                                                        $value = $defaultData[$field];
                                                                } else {
                                                                        // Hide at copy may override:
@@ -3347,9 +3348,10 @@ class DataHandler {
                $copyTablesArray = $this->admin ? $this->compileAdminTables() : explode(',', $this->BE_USER->groupData['tables_modify']);
                // If not all tables are allowed then make a list of allowed tables: That is the tables that figure in both allowed tables AND the copyTable-list
                if (!strstr($this->copyWhichTables, '*')) {
+                       $copyWhichTablesArray = array_flip(GeneralUtility::trimExplode(',', $this->copyWhichTables . ',pages'));
                        foreach ($copyTablesArray as $k => $table) {
                                // Pages are always going...
-                               if (!$table || !GeneralUtility::inList(($this->copyWhichTables . ',pages'), $table)) {
+                               if (!$table || !isset($copyWhichTablesArray[$table])) {
                                        unset($copyTablesArray[$k]);
                                }
                        }
@@ -5957,10 +5959,11 @@ class DataHandler {
         */
        public function getExcludeListArray() {
                $list = array();
+               $nonExcludeFieldsArray = array_flip(GeneralUtility::trimExplode(',', $this->BE_USER->groupData['non_exclude_fields']));
                foreach ($GLOBALS['TCA'] as $table => $_) {
                        if (isset($GLOBALS['TCA'][$table]['columns'])) {
                                foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $config) {
-                                       if ($config['exclude'] && !GeneralUtility::inList($this->BE_USER->groupData['non_exclude_fields'], ($table . ':' . $field))) {
+                                       if ($config['exclude'] && !isset($nonExcludeFieldsArray[$table . ':' . $field])) {
                                                $list[] = $table . '-' . $field;
                                        }
                                }