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

typo3/sysext/indexed_search/class.indexer.php
typo3/sysext/indexed_search/mod/index.php
typo3/sysext/indexed_search/modfunc1/class.tx_indexedsearch_modfunc1.php
typo3/sysext/indexed_search/pi/class.tx_indexedsearch.php

index c49dd18..ad73f7e 100755 (executable)
@@ -1187,8 +1187,7 @@ class tx_indexedsearch_indexer {
        function charsetEntity2utf8(&$contentArr, $charset)     {
 
                        // Convert charset if necessary
-               reset($contentArr);
-               while(list($key,)=each($contentArr)) {
+               foreach ($contentArr as $key => $value) {
                        if (strlen($contentArr[$key]))  {
 
                                if ($charset!=='utf-8') {
@@ -1210,8 +1209,7 @@ class tx_indexedsearch_indexer {
        function processWordsInArrays($contentArr)      {
 
                        // split all parts to words
-               reset($contentArr);
-               while(list($key,)=each($contentArr)) {
+               foreach ($contentArr as $key => $value) {
                        $contentArr[$key] = $this->lexerObj->split2Words($contentArr[$key]);
                }
 
@@ -1288,8 +1286,7 @@ class tx_indexedsearch_indexer {
         * @return      void
         */
        function analyzeHeaderinfo(&$retArr,$content,$key,$offset) {
-               reset($content[$key]);
-               while(list(,$val)=each($content[$key]))  {
+               foreach ($content[$key] as $val) {
                        $val = substr($val,0,60);       // Max 60 - because the baseword varchar IS 60. This MUST be the same.
                        $retArr[$val]['cmp'] = $retArr[$val]['cmp']|pow(2,$offset);
                        $retArr[$val]['count'] = $retArr[$val]['count']+1;
@@ -1879,9 +1876,8 @@ class tx_indexedsearch_indexer {
         * @return      void
         */
        function checkWordList($wl) {
-               reset($wl);
                $phashArr = array();
-               while(list($key,) = each($wl)) {
+               foreach ($wl as $key => $value) {
                        $phashArr[] = $wl[$key]['hash'];
                }
                if (count($phashArr))   {
@@ -1894,8 +1890,7 @@ class tx_indexedsearch_indexer {
                                        unset($wl[$row['baseword']]);
                                }
 
-                               reset($wl);
-                               while(list($key,$val)=each($wl)) {
+                               foreach ($wl as $key => $val) {
                                        $insertFields = array(
                                                'wid' => $val['hash'],
                                                'baseword' => $key,
index 3a3aebf..1d9f958 100755 (executable)
@@ -234,8 +234,7 @@ class SC_mod_tools_isearch_index {
        function getRecordsNumbers()    {
                $tables=explode(",","index_phash,index_words,index_rel,index_grlist,index_section,index_fulltext");
                $recList=array();
-               reset($tables);
-               while(list(,$t)=each($tables))  {
+               foreach ($tables as $t) {
                        $recList[] = array(
                                $this->tableHead($t),
                                $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $t)
@@ -435,9 +434,8 @@ class SC_mod_tools_isearch_index {
         * @return      [type]          ...
         */
        function formatFeGroup($fegroup_recs)   {
-               reset($fegroup_recs);
                $str = array();
-               while(list(,$row)=each($fegroup_recs))  {
+               foreach ($fegroup_recs as $row) {
                        $str[] = $row["gr_list"]=="0,-1" ? "NL" : $row["gr_list"];
                }
                arsort($str);
@@ -451,12 +449,11 @@ class SC_mod_tools_isearch_index {
         * @return      [type]          ...
         */
        function formatCHash($arr)      {
-               reset($arr);
-               $list=array();
-               while(list($k,$v)=each($arr))   {
-                       $list[]=$k."=".$v;
+               $list = array();
+               foreach ($arr as $k => $v) {
+                       $list[] = $k . '=' . $v;
                }
-               return implode("<BR>",$list);
+               return implode('<br />', $list);
        }
 
        /**
index 8437fbc..7b4f01a 100755 (executable)
@@ -1067,9 +1067,8 @@ class tx_indexedsearch_modfunc1 extends t3lib_extobjbase {
         */
        function printExtraGrListRows($extraGrListRows) {
                if (count($extraGrListRows))    {
-                       reset($extraGrListRows);
                        $lines=array();
-                       while(list(,$r)=each($extraGrListRows)) {
+                       foreach ($extraGrListRows as $r) {
                                $lines[] = $r['gr_list'];
                        }
                        return '<br />' . $GLOBALS['TBE_TEMPLATE']->dfw(implode('<br />', $lines));
index 3b76ab8..21ab7d4 100755 (executable)
@@ -344,13 +344,13 @@ class tx_indexedsearch extends tslib_pibase {
                        // This selects the first and secondary menus for the "sections" selector - so we can search in sections and sub sections.
                if ($this->conf['show.']['L1sections']) {
                        $firstLevelMenu = $this->getMenu($this->wholeSiteIdList);
-                       while(list($kk,$mR) = each($firstLevelMenu))    {
+                       foreach ($firstLevelMenu as $kk => $mR) {
                                        // @TODO: RFC #7370: doktype 2&5 are deprecated since TYPO3 4.2-beta1
                                if ($mR['doktype']!=5 && !$mR['nav_hide']) {
                                        $this->optValues['sections']['rl1_'.$mR['uid']] = trim($this->pi_getLL('opt_RL1').' '.$mR['title']);
                                        if ($this->conf['show.']['L2sections']) {
                                                $secondLevelMenu = $this->getMenu($mR['uid']);
-                                               while(list($kk2,$mR2) = each($secondLevelMenu)) {
+                                               foreach ($secondLevelMenu as $kk2 => $mR2) {
                                                                // @TODO: RFC #7370: doktype 2&5 are deprecated since TYPO3 4.2-beta1
                                                        if ($mR2['doktype']!=5 && !$mR2['nav_hide']) {
                                                                $this->optValues['sections']['rl2_'.$mR2['uid']] = trim($this->pi_getLL('opt_RL2').' '.$mR2['title']);
@@ -1085,7 +1085,7 @@ class tx_indexedsearch extends tslib_pibase {
                } elseif ($this->wholeSiteIdList>=0) {  // Collecting all pages IDs in which to search; filtering out ALL pages that are not accessible due to enableFields. Does NOT look for "no_search" field!
                        $siteIdNumbers = t3lib_div::intExplode(',',$this->wholeSiteIdList);
                        $id_list=array();
-                       while(list(,$rootId)=each($siteIdNumbers))      {
+                       foreach ($siteIdNumbers as $rootId) {
                                $id_list[] = $this->cObj->getTreeList($rootId,9999,0,0,'','').$rootId;
                        }
                        $page_where = 'ISEC.page_id IN ('.implode(',',$id_list).')';
@@ -2299,8 +2299,7 @@ class tx_indexedsearch extends tslib_pibase {
                        $hitRoot = 0;
                        $path = '';
                        if (is_array($rl) && count($rl))        {
-                               reset($rl);
-                               while(list($k,$v)=each($rl))    {
+                               foreach ($rl as $k => $v) {
                                                // Check fe_user
                                        if ($v['fe_group'] && ($v['uid']==$id || $v['extendToSubpages']))       {
                                                $this->fe_groups_required[$id][]=$v['fe_group'];