Bug #20745
closedreplace while(list()...) by foreach in the TYPO3 core part 1
0%
Description
Problem:
foreach() has proven1 that it is way faster than while(list()=each()) and in current PHP versions foreach even needs less memory.
Solution:
replace while(list()=each()) with the appropriate foreach() statements in frontend classes
(part 2 will take care of the rest)
[1]
http://lists.typo3.org/pipermail/typo3-dev/2009-June/035735.html
the patch affects the following files:
t3lib/class.t3lib_page.php
t3lib/class.t3lib_tsparser.php
typo3/sysext/cms/tslib/class.tslib_menu.php
typo3/sysext/cms/tslib/class.tslib_pagegen.php
typo3/sysext/cms/tslib/class.tslib_content.php
that what I changed:
variant 1
- reset($array);
- while(list($k)=each($array)) {
+ foreach ($array as $k => $v) {
this leaves $v unused but in this way it is faster than while(list()...) or calling array_keys() before
variant 2
- reset($loadDB->tableArray);
- while(list($table,)=each($loadDB->tableArray)) {
+ foreach ($loadDB->tableArray as $table => $v) {
same as variant 1
variant 3
- reset($Hobjs);
- while(list(,$index)=each($Hobjs)) {
+ foreach ($Hobjs as $index) {
variant 4
- reset($inArray);
- while(list($fN,$fV)=each($inArray)) {
+ foreach ($inArray as $fN => $v) {
in some cases I changed lines where very deep arrays where accessed during loops to use a local copy of this array instead.
performance gain of this patch depends very much on your sites settings - will say: if you have a big menu the changes in class.tslib_menu will have much more impact than with a small one.
I tested it with a (uncached) page which displays 4 tt_news plugins calling cobj->getmarkerArrayCached() hundreds of times and I got a performance gain of 7-10%
(issue imported from #M11512)
Files
Updated by Rupert Germann over 15 years ago
added v2 which fixes a bug in tslib_content function SEARCHRESULT
Updated by Rupert Germann over 15 years ago
committed to trunk rev 5764
final patch v3a attached
Updated by Chris topher over 12 years ago
- Category deleted (
Communication) - Target version deleted (
-1) - TYPO3 Version set to 4.3