From ea046a7730b5a963ba49b50ba8f6af8673d6928c Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Mon, 17 Sep 2012 01:13:35 +0000 Subject: [PATCH] Otimização dos loops do tipo for( nos programas PHP --- classesphp/classe_alteraclasse.php | 2 +- classesphp/classe_atlas.php | 4 ++-- classesphp/classe_atributos.php | 6 +++--- classesphp/classe_imagem.php | 42 +++++++++++++++++++++--------------------- classesphp/classe_legenda.php | 2 +- classesphp/classe_vermultilayer.php | 2 +- classesphp/funcoes_gerais.php | 8 ++++---- classesphp/graficopizza.php | 4 ++-- classesphp/mapa_controle.php | 2 +- classesphp/mapa_googleearth.php | 2 +- classesphp/mapa_googlemaps.php | 4 ++-- classesphp/mapa_inicia.php | 2 +- classesphp/mapa_openlayers.php | 2 +- 13 files changed, 41 insertions(+), 41 deletions(-) diff --git a/classesphp/classe_alteraclasse.php b/classesphp/classe_alteraclasse.php index b17b126..f3a144b 100644 --- a/classesphp/classe_alteraclasse.php +++ b/classesphp/classe_alteraclasse.php @@ -120,7 +120,7 @@ cores {array} - array com a lista de valores RGB $numclasses = $this->layer->numclasses; if ($numclasses > 0) { - for ($i=0; $i < $numclasses; $i++) + for ($i=0; $i < $numclasses; ++$i) { $classe = $this->layer->getClass($i); $estilo = $classe->getstyle(0); diff --git a/classesphp/classe_atlas.php b/classesphp/classe_atlas.php index c6ea518..1d5a344 100644 --- a/classesphp/classe_atlas.php +++ b/classesphp/classe_atlas.php @@ -153,7 +153,7 @@ locaplic - localização do i3geo no servidor $layers = array(); $mapa = ms_newMapObj($map_file); $numlayers = $mapa->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $l = $mapa->getlayer($i); if (($l->getmetadata("ATLAS")) != "nao") @@ -206,7 +206,7 @@ locaplic - localização do i3geo no servidor $mapa = ms_newMapObj($map_file); $numlayers = $mapa->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $l = $mapa->getlayer($i); if (($l->getmetadata("ATLAS")) != "nao") diff --git a/classesphp/classe_atributos.php b/classesphp/classe_atributos.php index 82a1ef3..eb44d64 100644 --- a/classesphp/classe_atributos.php +++ b/classesphp/classe_atributos.php @@ -553,7 +553,7 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) if (@$l->queryByrect($ret) == MS_SUCCESS) { $res_count = $l->getNumresults(); - for ($i = 0; $i < $res_count; $i++) + for ($i = 0; $i < $res_count; ++$i) { $valitem = array(); if($this->v == 6){ @@ -743,7 +743,7 @@ $resolucao - Resolucao de busca. function identifica($opcao,$xy,$resolucao) { $numlayers = $mapa->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $layer = $mapa->getlayer($i); $tem = $l->name; @@ -973,7 +973,7 @@ $wkt - (opcional) {boolean} inclui ou não o valor do wkt da geometria { $ltemp = array(); $numlayers = $this->mapa->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $tl = $this->mapa->getlayer($i); $tema = $tl->name; diff --git a/classesphp/classe_imagem.php b/classesphp/classe_imagem.php index cc95a91..55fb0a1 100644 --- a/classesphp/classe_imagem.php +++ b/classesphp/classe_imagem.php @@ -39,26 +39,26 @@ class Imagem { /* Variavel: $arquivoimg - + Arquivo de imagem */ protected $arquivoimg; /* Variavel: $img - + Objeto imagem */ protected $img; - + /* Function: __construct -Cria um objeto imagem +Cria um objeto imagem parameters: $arquivo - Nome completo da imagem em disco. -*/ +*/ function __construct($arquivo) { //error_reporting(E_ALL); @@ -67,7 +67,7 @@ $arquivo - Nome completo da imagem em disco. $this->arquivoimg = $arquivo; $this->img = imagecreatefrompng($arquivo); imagealphablending($this->img, false); - imagesavealpha($this->img, true); + imagesavealpha($this->img, true); } else {return null;} @@ -75,12 +75,12 @@ $arquivo - Nome completo da imagem em disco. /* function: fundeIm -Funde duas imagens +Funde duas imagens parameters: $ims: arquivo com a imagem que será sobreposta a atual -*/ +*/ function fundeIm($ims) { if (file_exists($ims)) @@ -102,8 +102,8 @@ $ims: arquivo com a imagem que será sobreposta a atual /* function: cortaBorda -Corta as bordas da imagem baseando-se no primeiro pixel -*/ +Corta as bordas da imagem baseando-se no primeiro pixel +*/ function cortaBorda() { $sx = imagesx($this->img); @@ -111,9 +111,9 @@ Corta as bordas da imagem baseando-se no primeiro pixel $corBase = imagecolorat($this->img, 0, 0); $linhai = 0; //pega a linha inicial - for ($y = 0; $y < $sy; $y++) + for ($y = 0; $y < $sy; ++$y) { - for ($x = 0; $x < $sx; $x++) + for ($x = 0; $x < $sx; ++$x) { if (imagecolorat($this->img, $x, $y) != $corBase) {$linhai = $y - 1;break;} @@ -121,9 +121,9 @@ Corta as bordas da imagem baseando-se no primeiro pixel if ($linhai != 0){break;} } //pega a coluna inicial - for ($x = 0; $x < $sx; $x++) + for ($x = 0; $x < $sx; ++$x) { - for ($y = 0; $y < $sy; $y++) + for ($y = 0; $y < $sy; ++$y) { if (imagecolorat($this->img, $x, $y) != $corBase) {$colunai = $x - 1;break;} @@ -133,7 +133,7 @@ Corta as bordas da imagem baseando-se no primeiro pixel //pega a linha final for ($y = $sy - 1; $y > 0; $y--) { - for ($x = 0; $x < $sx; $x++) + for ($x = 0; $x < $sx; ++$x) { if (imagecolorat($this->img, $x, $y) != $corBase) {$linhaf = $y + 1;break;} @@ -143,7 +143,7 @@ Corta as bordas da imagem baseando-se no primeiro pixel //pega a coluna final for ($x = $sx - 1; $x > 0; $x--) { - for ($y = 0; $y < $sy; $y++) + for ($y = 0; $y < $sy; ++$y) { if (imagecolorat($this->img, $x, $y) != $corBase) {$colunaf = $x + 15;break;} @@ -159,7 +159,7 @@ function: cinzaNormal Converte a imagem atual em tons de cinza -*/ +*/ function cinzaNormal() { imagefilter($this->img, IMG_FILTER_GRAYSCALE); @@ -174,9 +174,9 @@ Converte para sépia clara { $sx = imagesx($this->img); $sy = imagesy($this->img); - for ($x = 0; $x < $sx; $x++) + for ($x = 0; $x < $sx; ++$x) { - for ($y = 0; $y < $sy; $y++) + for ($y = 0; $y < $sy; ++$y) { $rgb = imagecolorat($this->img, $x, $y); $n = min(255,abs((($rgb >> 16) & 0xFF) * .229 + (($rgb >> 8) & 0xFF) * .587 + ($rgb & 0xFF) * .114) + 20); @@ -197,9 +197,9 @@ Converte para sépia normal { $sx = imagesx($this->img); $sy = imagesy($this->img); - for ($x = 0; $x < $sx; $x++) + for ($x = 0; $x < $sx; ++$x) { - for ($y = 0; $y < $sy; $y++) + for ($y = 0; $y < $sy; ++$y) { $rgb = imagecolorat($this->img, $x, $y); $n = min(255,abs((($rgb >> 16) & 0xFF) * .229 + (($rgb >> 8) & 0xFF) * .587 + ($rgb & 0xFF) * .114) + 3); diff --git a/classesphp/classe_legenda.php b/classesphp/classe_legenda.php index 80f6914..615b3fe 100644 --- a/classesphp/classe_legenda.php +++ b/classesphp/classe_legenda.php @@ -270,7 +270,7 @@ string de variaveis no formato javascript que permitem montar a legenda. function legendaGrafica() { $numlayers = $this->$mapa->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $layer = $this->$mapa->getlayer($i); if (($layer->data != "") && (strtoupper($layer->getmetadata("escondido")) != "SIM") && (strtoupper($layer->getmetadata("tema")) != "NAO")) diff --git a/classesphp/classe_vermultilayer.php b/classesphp/classe_vermultilayer.php index eac2e36..65b5ecd 100644 --- a/classesphp/classe_vermultilayer.php +++ b/classesphp/classe_vermultilayer.php @@ -97,7 +97,7 @@ class vermultilayer $temasvisiveis = array(); $numlayers = $map->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $layer = $map->getlayer($i); $temai = $layer->name; diff --git a/classesphp/funcoes_gerais.php b/classesphp/funcoes_gerais.php index d657480..23f5a60 100644 --- a/classesphp/funcoes_gerais.php +++ b/classesphp/funcoes_gerais.php @@ -204,7 +204,7 @@ function criaImagemR($nomearq) $trans = 250 / ($maxpixel - $minpixel); $img = imagecreatetruecolor($wh[0],$wh[1]); $celula = 0; - for ($x = 0; $x < $wh[0]; $x++) + for ($x = 0; $x < $wh[0]; ++$x) { for ($y = ($wh[1] - 1); $y >= 0; $y--) { @@ -2101,7 +2101,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) { $maptemp = ms_newMapObj($temasdir."/".$tema.".map"); $numlayers = $maptemp->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $ll = $maptemp->getlayer($i); $permite = $ll->getmetadata("permitedownload"); @@ -2256,7 +2256,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) if(file_exists($temasdir."/".$tema.".map")){ $maptemp = ms_newMapObj($temasdir."/".$tema.".map"); $numlayers = $maptemp->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $gl = $maptemp->getlayer($i); $gl->set("data",""); @@ -2916,7 +2916,7 @@ $map_file - arquivo mapfile que será processado function sobeAnno($map_file){ $mapa = ms_newMapObj($map_file); $numlayers = $mapa->numlayers; - for ($i=0;$i<$numlayers;$i++){ + for ($i=0;$i<$numlayers;++$i){ $layer = $mapa->getlayer($i); if($layer->type == 4){ $temp = ms_newLayerObj($mapa,$layer); diff --git a/classesphp/graficopizza.php b/classesphp/graficopizza.php index 41ae2fe..311f84e 100644 --- a/classesphp/graficopizza.php +++ b/classesphp/graficopizza.php @@ -109,12 +109,12 @@ function graficopizza($data,$width,$inclinacao,$shadow_height,$cores,$map_file,$ } for ($i=$centerY+$shadow_height; $i>$centerY; $i--) { - for ($j = 0; $j < count($slice); $j++) + for ($j = 0; $j < count($slice); ++$j) { ImageFilledArc($img, $centerX, $i, $diameterX, $diameterY, $slice[$j][0], $slice[$j][1], $slice[$j][2], IMG_ARC_PIE); } } - for ($j = 0; $j < count($slice); $j++) + for ($j = 0; $j < count($slice); ++$j) { ImageFilledArc($img, $centerX, $centerY, $diameterX, $diameterY, $slice[$j][0], $slice[$j][1], $slice[$j][3], IMG_ARC_PIE); } diff --git a/classesphp/mapa_controle.php b/classesphp/mapa_controle.php index b7c173f..24ab5d8 100644 --- a/classesphp/mapa_controle.php +++ b/classesphp/mapa_controle.php @@ -153,7 +153,7 @@ if (isset($debug) && strtolower($debug) == "sim") // //teste de timeout // -//for($i==0;$i<5000000000;$i++){} +//for($i==0;$i<5000000000;++$i){} // //ativa o php mapscript e as extensões necessárias //se as extensões já estiverem carregadas no PHP, vc pode comentar essa linha para que o processamento fique mais rápido diff --git a/classesphp/mapa_googleearth.php b/classesphp/mapa_googleearth.php index 5247d77..9b3fb98 100644 --- a/classesphp/mapa_googleearth.php +++ b/classesphp/mapa_googleearth.php @@ -120,7 +120,7 @@ function retornaWms($map_fileX,$postgis_mapa){ $o->set("imagemode",MS_IMAGEMODE_RGBA); if(!isset($_GET["telaR"])){//no caso de projecoes remotas, o mapfile nao´e alterado $numlayers = $mapa->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $l = $mapa->getlayer($i); if ($l->getmetadata("classesnome") != "") diff --git a/classesphp/mapa_googlemaps.php b/classesphp/mapa_googlemaps.php index da88362..e356b84 100644 --- a/classesphp/mapa_googlemaps.php +++ b/classesphp/mapa_googlemaps.php @@ -130,7 +130,7 @@ $cache = false; if(!isset($_GET["telaR"])){//no caso de projecoes remotas, o mapfile nao´e alterado $numlayers = $mapa->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $l = $mapa->getlayer($i); $layerName = $l->name; @@ -178,7 +178,7 @@ if(!isset($_GET["telaR"])){//no caso de projecoes remotas, o mapfile nao´e alter else{ $mapa->setProjection("proj=merc,a=6378137,b=6378137,lat_ts=0.0,lon_0=0.0,x_0=0.0,y_0=0,k=1.0,units=m"); $numlayers = $mapa->numlayers; - for ($i=0;$i < $numlayers;$i++) + for ($i=0;$i < $numlayers;++$i) { $l = $mapa->getlayer($i); if($l->getProjection() == "" ) diff --git a/classesphp/mapa_inicia.php b/classesphp/mapa_inicia.php index 1b00af0..7a24e8c 100644 --- a/classesphp/mapa_inicia.php +++ b/classesphp/mapa_inicia.php @@ -244,7 +244,7 @@ function iniciaMapa() $m->mapa->save($nomefundo); $mf = ms_newMapObj($nomefundo); $numlayers = $mf->numlayers; - for($i = 0;$i < $numlayers;$i++) + for($i = 0;$i < $numlayers;++$i) { $l = $mf->getLayer($i); $l->set("status",MS_DELETE); diff --git a/classesphp/mapa_openlayers.php b/classesphp/mapa_openlayers.php index d9fdcd4..f738d44 100644 --- a/classesphp/mapa_openlayers.php +++ b/classesphp/mapa_openlayers.php @@ -84,7 +84,7 @@ $qy = file_exists($qyfile); if(!isset($_GET["telaR"])){//no caso de projecoes remotas, o mapfile nao e alterado $numlayers = $mapa->numlayers; $cache = false; - for($i = 0;$i < $numlayers;$i++) + for($i = 0;$i < $numlayers;++$i) { $l = $mapa->getLayer($i); if ($l->getmetadata("classesnome") != "") -- libgit2 0.21.2