Fixed issue #13670: Performance optimization: change while(list() to foreach() (thank...
authorErnesto Baschny <ernst@cron-it.de>
Thu, 13 May 2010 17:12:06 +0000 (17:12 +0000)
committerErnesto Baschny <ernst@cron-it.de>
Thu, 13 May 2010 17:12:06 +0000 (17:12 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7593 709f56b5-9817-0410-a4d7-c38de5d9e867

typo3/alt_clickmenu.php
typo3/class.alt_menu_functions.inc
typo3/class.browse_links.php
typo3/class.db_list.inc
typo3/class.file_list.inc
typo3/db_list.php
typo3/file_list.php
typo3/view_help.php
typo3/wizard_table.php
typo3/wizard_tsconfig.php

index 8e2fcae..3d01617 100644 (file)
@@ -408,8 +408,7 @@ class clickMenu {
         */
        function processingByExtClassArray($menuItems,$table,$uid)      {
                if (is_array($this->extClassArray))     {
-                       reset($this->extClassArray);
-                       while(list(,$conf)=each($this->extClassArray))  {
+                       foreach ($this->extClassArray as $conf) {
                                $obj=t3lib_div::makeInstance($conf['name']);
                                $menuItems = $obj->main($this,$menuItems,$table,$uid);
                        }
@@ -1292,9 +1291,8 @@ class clickMenu {
         * @return      array           Array of menu items for top frame.
         */
        function menuItemsForTopFrame($menuItems)       {
-               reset($menuItems);
                $out=array();
-               while(list(,$i)=each($menuItems))       {
+               foreach ($menuItems as $i) {
                        if ($i[4]==1 && !$GLOBALS['SOBE']->doc->isCMlayers())   $i[4]=0;        // IF the topbar is the ONLY means of the click menu, then items normally disabled from the top menu will appear anyways IF they are disabled with a "1" (2+ will still disallow them in the topbar)
                        if (is_array($i) && !$i[4])     $out[]=$i[0];
                }
@@ -1309,9 +1307,8 @@ class clickMenu {
         * @return      array           array for implosion in the CM div-layers table.
         */
        function menuItemsForClickMenu($menuItems)      {
-               reset($menuItems);
                $out=array();
-               while(list($cc,$i)=each($menuItems))    {
+               foreach ($menuItems as $cc => $i) {
                        if (is_string($i) && $i=='spacer')      {       // MAKE horizontal spacer
                                $out[]='
                                        <tr class="bgColor2">
index 1667aa7..653d2ea 100644 (file)
@@ -142,8 +142,7 @@ class alt_menu_functions {
                }
 
                        // Traverse array with modules
-               reset($theModules);
-               while(list($moduleName,$moduleInfo)=each($theModules))  {
+               foreach ($theModules as $moduleName => $moduleInfo) {
                        $mC++;
 
                        $prefix = $this->getNavFramePrefix($moduleInfo);
@@ -239,10 +238,9 @@ class alt_menu_functions {
                                // Traversing submodules
                        $subCode='';
                        if (is_array($moduleInfo['sub']))       {
-                               reset($moduleInfo['sub']);
                                $collection[$moduleKey]['subitems'] = array();
                                $c=0;
-                               while(list($subName,$subInfo)=each($moduleInfo['sub'])) {
+                               foreach ($moduleInfo['sub'] as $subName => $subInfo) {
                                        if ($c==0)              {
                                                $subCode.='
                                                                <tr class="c-first">
index 5584435..6072e40 100644 (file)
@@ -917,9 +917,8 @@ class browse_links {
 
                if ($this->mode == 'wizard')    {       // Functions used, if the link selector is in wizard mode (= TCEforms fields)
                        unset($this->P['fieldChangeFunc']['alert']);
-                       reset($this->P['fieldChangeFunc']);
                        $update='';
-                       while(list($k,$v)=each($this->P['fieldChangeFunc']))    {
+                       foreach ($this->P['fieldChangeFunc'] as $k => $v) {
                                $update.= '
                                window.opener.'.$v;
                        }
@@ -1364,8 +1363,7 @@ class browse_links {
                                if (is_array($this->thisConfig['userLinks.']))  {
                                        $subcats=array();
                                        $v=$this->thisConfig['userLinks.'];
-                                       reset($v);
-                                       while(list($k2)=each($v))       {
+                                       foreach ($v as $k2 => $value) {
                                                $k2i = intval($k2);
                                                if (substr($k2,-1)=='.' && is_array($v[$k2i.'.']))      {
 
@@ -2395,7 +2393,7 @@ class browse_links {
                                                </tr>';
 
                                                // Traverse files:
-                                       while(list(,$filepath)=each($files))    {
+                                       foreach ($files as $filepath) {
                                                $fI = pathinfo($filepath);
 
                                                        // URL of image:
index 5a7a532..03d39cd 100644 (file)
@@ -243,8 +243,7 @@ class recordList extends t3lib_recordList {
                $this->pageRecord = t3lib_BEfunc::getRecordWSOL('pages',$this->id);
 
                        // Traverse the TCA table array:
-               reset($TCA);
-               while (list($tableName)=each($TCA))     {
+               foreach ($TCA as $tableName => $value) {
 
                                // Checking if the table should be rendered:
                        if ((!$this->table || $tableName==$this->table) && (!$this->tableList || t3lib_div::inList($this->tableList,$tableName)) && $GLOBALS['BE_USER']->check('tables_select',$tableName))     {               // Checks that we see only permitted/requested tables:
@@ -322,7 +321,7 @@ class recordList extends t3lib_recordList {
                        // Make level selector:
                $opt=array();
                $parts = explode('|',$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.enterSearchLevels'));
-               while(list($kv,$label)=each($parts))    {
+               foreach ($parts as $kv => $label) {
                        $opt[] = '<option value="'.$kv.'"'.($kv==intval($this->searchLevels)?' selected="selected"':'').'>'.htmlspecialchars($label).'</option>';
                }
                $lMenu = '<select name="search_levels">'.implode('',$opt).'</select>';
index 2f56814..5dfe416 100644 (file)
@@ -319,8 +319,7 @@ class fileList extends t3lib_recordList {
 
                // Folders:
                if (count($items['sorting']))   {
-                       reset($items['sorting']);
-                       while (list($key,) = each($items['sorting']))   {
+                       foreach ($items['sorting'] as $key => $value) {
                                list($flag,$code) = $this->fwd_rwd_nav();
                                $out.=$code;
                                if ($flag)      {
@@ -336,8 +335,7 @@ class fileList extends t3lib_recordList {
 
                                                //      Preparing and getting the data-array
                                        $theData = Array();
-                                       reset($this->fieldArray);
-                                       while(list(,$field)=each($this->fieldArray))    {
+                                       foreach ($this->fieldArray as $field) {
                                                switch($field)  {
                                                        case 'size':
                                                                $theData[$field] = t3lib_div::formatSize($theFile[$field], $GLOBALS['LANG']->getLL('byteSizeUnits', true));
@@ -462,8 +460,7 @@ class fileList extends t3lib_recordList {
 
                        // Files:
                if (count($items['sorting']))   {
-                       reset($items['sorting']);
-                       while (list($key,) = each($items['sorting']))   {
+                       foreach ($items['sorting'] as $key => $value) {
                                list($flag,$code) = $this->fwd_rwd_nav();
                                $out.=$code;
                                if ($flag)      {
@@ -481,8 +478,7 @@ class fileList extends t3lib_recordList {
 
                                                //      Preparing and getting the data-array
                                        $theData = Array();
-                                       reset($this->fieldArray);
-                                       while(list(,$field)=each($this->fieldArray))    {
+                                       foreach ($this->fieldArray as $field) {
                                                switch($field)  {
                                                        case 'size':
                                                                $theData[$field] = t3lib_div::formatSize($theFile[$field], $GLOBALS['LANG']->getLL('byteSizeUnits', true));
@@ -605,8 +601,7 @@ class fileList extends t3lib_recordList {
                                $d->close();
                        }
                                // Get fileinfo
-                       reset($tempArray);
-                       while (list(,$val)=each($tempArray))    {
+                       foreach ($tempArray as $val) {
                                $temp = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($val);
                                $items['files'][] = $temp;
                                if ($this->sort)        {
index 1967ed4..bdc8da5 100644 (file)
@@ -260,8 +260,7 @@ class SC_db_list {
                                $items = $dblist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),$this->cmd_table,1);
                                if (count($items))      {
                                        $cmd=array();
-                                       reset($items);
-                                       while(list($iK)=each($items))   {
+                                       foreach ($items as $iK => $value) {
                                                $iKParts = explode('|',$iK);
                                                $cmd[$iKParts[0]][$iKParts[1]]['delete']=1;
                                        }
index 04c427f..ada3f2c 100644 (file)
@@ -262,8 +262,7 @@ class SC_file_list {
                                if (count($items))      {
                                                // Make command array:
                                        $FILE=array();
-                                       reset($items);
-                                       while(list(,$v)=each($items))   {
+                                       foreach ($items as $v) {
                                                $FILE['delete'][]=array('data'=>$v);
                                        }
 
index a594ffc..782ac87 100644 (file)
@@ -434,8 +434,7 @@ class SC_view_help {
                        $parts[0] = ''; // Reserved for header of table
 
                                // Traverse table columns as listed in TCA_DESCR
-                       reset($TCA_DESCR[$table]['columns']);
-                       while(list($field) = each($TCA_DESCR[$table]['columns']))       {
+                       foreach ($TCA_DESCR[$table]['columns'] as $field => $value) {
 
                                $fieldValue = isset($TCA[$table]) && strcmp($field,'') ? $TCA[$table]['columns'][$field] : array();
 
@@ -797,8 +796,7 @@ class SC_view_help {
                                        if (is_array($TCA_DESCR[$cshKey]['columns']))   {
 
                                                        // Traverse table columns as listed in TCA_DESCR
-                                               reset($TCA_DESCR[$cshKey]['columns']);
-                                               while(list($field,$data) = each($TCA_DESCR[$cshKey]['columns']))        {
+                                               foreach ($TCA_DESCR[$cshKey]['columns'] as $field => $data) {
                                                        if ($field)     {
                                                                $this->glossaryWords[$cshKey.'.'.$field] = array(
                                                                        'title' => trim($data['alttitle'] ? $data['alttitle'] : $cshKey),
index 7da8e1a..b0dfed9 100644 (file)
@@ -552,8 +552,7 @@ class SC_wizard_table {
                                ksort($this->TABLECFG['c']);
                        }
                        if (substr($cmd,0,4)=='col_')   {
-                               reset($this->TABLECFG['c']);
-                               while(list($cAK)=each($this->TABLECFG['c']))    {
+                               foreach ($this->TABLECFG['c'] as $cAK => $value) {
                                        switch($cmd)    {
                                                case 'col_remove':
                                                        unset($this->TABLECFG['c'][$cAK][$kk]);
@@ -584,10 +583,8 @@ class SC_wizard_table {
                }
 
                // Convert line breaks to <br /> tags:
-               reset($this->TABLECFG['c']);
-               while(list($a)=each($this->TABLECFG['c']))      {
-                       reset($this->TABLECFG['c'][$a]);
-                       while(list($b)=each($this->TABLECFG['c'][$a]))  {
+               foreach ($this->TABLECFG['c'] as $a => $value) {
+                       foreach ($this->TABLECFG['c'][$a] as $b => $value2) {
                                $this->TABLECFG['c'][$a][$b] = str_replace(LF,'<br />',str_replace(CR,'',$this->TABLECFG['c'][$a][$b]));
                        }
                }
@@ -606,11 +603,9 @@ class SC_wizard_table {
                $inLines=array();
 
                        // Traverse the elements of the table wizard and transform the settings into configuration code.
-               reset($this->TABLECFG['c']);
-               while(list($a)=each($this->TABLECFG['c']))      {
+               foreach ($this->TABLECFG['c'] as $a => $value) {
                        $thisLine=array();
-                       reset($this->TABLECFG['c'][$a]);
-                       while(list($b)=each($this->TABLECFG['c'][$a]))  {
+                       foreach ($this->TABLECFG['c'][$a] as $b => $value) {
                                $thisLine[]=$this->tableParsing_quote.str_replace($this->tableParsing_delimiter,'',$this->TABLECFG['c'][$a][$b]).$this->tableParsing_quote;
                        }
                        $inLines[]=implode($this->tableParsing_delimiter,$thisLine);
index d94ad6c..30cb186 100644 (file)
@@ -423,10 +423,10 @@ class SC_wizard_tsconfig {
                while($rec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
                        $rec['obj_string'] = $this->revertFromSpecialChars($rec['obj_string']);
                        $p = explode(';',$rec['obj_string']);
-                       while(list(,$v)=each($p))       {
+                       foreach ($p as $v) {
                                $p2 = t3lib_div::trimExplode(':',$v,1);
                                $subp=t3lib_div::trimExplode('/',$p2[1],1);
-                               while(list(,$v2)=each($subp))   {
+                               foreach ($subp as $v2) {
                                        $this->setObj($objTree,explode('.',$p2[0].'.'.$v2),array($rec,$v2));
                                }
                        }
@@ -492,8 +492,7 @@ class SC_wizard_tsconfig {
         * @access private
         */
        function removePointerObjects($objArray)        {
-               reset($objArray);
-               while(list($k)=each($objArray)) {
+               foreach ($objArray as $k => $value) {
                        if (substr(trim($k),0,2)=="->" && trim($k)!='->.')      {
                                $objArray['->.'][substr(trim($k),2)]=$objArray[$k];
                                unset($objArray[$k]);
@@ -551,7 +550,7 @@ class SC_wizard_tsconfig {
                                        // Linking:
                                $lP=t3lib_div::trimExplode(LF,$row['property'],1);
                                $lP2=array();
-                               while(list($k,$lStr)=each($lP)) {
+                               foreach ($lP as $k => $lStr) {
                                        $lP2[$k] = $this->linkProperty($lStr,$lStr,$objString,$row['datatype']);
                                }
                                $linkedProperties=implode('<hr />',$lP2);