Project

General

Profile

Actions

Task #55626

closed

Replace GeneralUtility::inList with isset() for lists of values being static or within loops

Added by Jo Hasenau over 10 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Must have
Category:
Performance
Target version:
-
Start date:
2014-02-03
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
7
PHP Version:
5.4
Tags:
Complexity:
Sprint Focus:

Description

There are about 250 places in the core making use of GeneralUtility::inList

GeneralUtility::inList('formtype_mail,subject,html_enabled', $confData['fieldname']));
GeneralUtility::inList($listToCheck, $confData['fieldname']));

On the one hand this is quite fast and handy, when you are checking variable lists of values just once.
But while checking variable lists that are used within a loop or static lists of know values, it would be much faster and less memory consuming to make use of an array with appropriate keys and isset();

Just two simple use cases with loops:

$listArrayToCheck = array_flip(explode(',', $listToCheck));
foreach($whatever as $value) {
  if(isset($listArrayToCheck[$value])) {}
}

or

$listArrayToCheck = array_flip(array(
    'formtype_mail', 'subject', 'html_enabled'
));
foreach($whatever as $value) {
  if(isset($listArrayToCheck[$value])) {}
}

would be better than

foreach($whatever as $value) {
  GeneralUtility::inList($listToCheck, $value);
}

And a use case for a single check of a known static list:

$listArrayToCheck = array_flip(array(
    'formtype_mail', 'subject', 'html_enabled'
));
if(isset($listArrayToCheck[$value]));

So the rule of thumb should be to use GeneralUtility::inList for single checks of lists with unknown values only.
Of course the array_flip could be avoided as well for the use case with known list values, but this would sacrifice readability for performance.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #72818: External links including ".php" rendered without httpClosedMarkus Klein2016-01-19

Actions
Actions

Also available in: Atom PDF