Project

General

Profile

Actions

Bug #20745

closed

replace while(list()...) by foreach in the TYPO3 core part 1

Added by Rupert Germann over 15 years ago. Updated over 12 years ago.

Status:
Closed
Priority:
Should have
Category:
-
Target version:
-
Start date:
2009-07-13
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.3
PHP Version:
4.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

11512_while_foreach_p1_v2.diff (36.3 KB) 11512_while_foreach_p1_v2.diff Administrator Admin, 2009-07-17 15:29
11512_while_foreach_p1_v3a.diff (36.8 KB) 11512_while_foreach_p1_v3a.diff Administrator Admin, 2009-08-05 13:33
Actions

Also available in: Atom PDF