From 5f3b9d2aff033c2b5a8077bfbaf94d9c19a8ef1f Mon Sep 17 00:00:00 2001 From: Weshley Date: Tue, 3 Nov 2020 12:20:14 -0600 Subject: [PATCH] Moved increment operator to preceed variables rather than follow for speed improvements. --- audit.php | 2 +- base.php | 12 ++++++------ bcrypt.php | 4 ++-- cli/ws.php | 6 +++--- db/jig/mapper.php | 2 +- db/sql.php | 2 +- db/sql/mapper.php | 6 +++--- image.php | 14 +++++++------- matrix.php | 2 +- template.php | 2 +- web.php | 24 ++++++++++++------------ web/openid.php | 2 +- 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/audit.php b/audit.php index 8fcc95ae..a0d4338e 100644 --- a/audit.php +++ b/audit.php @@ -145,7 +145,7 @@ function mod10($id) { return FALSE; $id=strrev($id); $sum=0; - for ($i=0,$l=strlen($id);$i<$l;$i++) + for ($i=0,$l=strlen($id);$i<$l;++$i) $sum+=$id[$i]+$i%2*(($id[$i]>4)*-4+$id[$i]%5); return !($sum%10); } diff --git a/base.php b/base.php index 19e4770c..42ac093f 100644 --- a/base.php +++ b/base.php @@ -186,7 +186,7 @@ function($match) use(&$i,$args) { array_key_exists($match[3],$args)) { if (!is_array($args[$match[3]])) return $args[$match[3]]; - $i++; + ++$i; return $args[$match[3]][$i-1]; } return $match[0]; @@ -1620,7 +1620,7 @@ function mask($pattern,$url=NULL) { $i=0; while (is_int($pos=strpos($wild,'\*'))) { $wild=substr_replace($wild,'(?P<_'.$i.'>[^\?]*)',$pos,2); - $i++; + ++$i; } preg_match('/^'. preg_replace( @@ -1772,7 +1772,7 @@ function($id) use($args) { $ctr=0; foreach (str_split($body,1024) as $part) { // Throttle output - $ctr++; + ++$ctr; if ($ctr/$kbps>($elapsed=microtime(TRUE)-$now) && !connection_aborted()) usleep(1e6*($ctr/$kbps-$elapsed)); @@ -2354,7 +2354,7 @@ function($level,$text,$file,$line) { // Emulate HTTP request $_SERVER['REQUEST_METHOD']='GET'; if (!isset($_SERVER['argv'][1])) { - $_SERVER['argc']++; + ++$_SERVER['argc']; $_SERVER['argv'][1]='/'; } $req=$query=''; @@ -2745,7 +2745,7 @@ function reset($suffix=NULL) { case 'xcache': if ($suffix && !ini_get('xcache.admin.enable_auth')) { $cnt=xcache_count(XC_TYPE_VAR); - for ($i=0;$i<$cnt;$i++) { + for ($i=0;$i<$cnt;++$i) { $list=xcache_list(XC_TYPE_VAR,$i); foreach ($list['cache_list'] as $item) if (preg_match($regex,$item['name'])) @@ -2903,7 +2903,7 @@ protected function sandbox(array $hive=NULL,$mime=NULL) { unset($fw,$hive,$implicit,$mime); extract($this->temp); $this->temp=NULL; - $this->level++; + ++$this->level; ob_start(); require($this->file); $this->level--; diff --git a/bcrypt.php b/bcrypt.php index f044ff1d..414daa73 100644 --- a/bcrypt.php +++ b/bcrypt.php @@ -56,7 +56,7 @@ function hash($pw,$salt=NULL,$cost=self::COST) { if (!$iv && extension_loaded('openssl')) $iv=openssl_random_pseudo_bytes($raw); if (!$iv) - for ($i=0;$i<$raw;$i++) + for ($i=0;$i<$raw;++$i) $iv.=chr(mt_rand(0,255)); $salt=str_replace('+','.',base64_encode($iv)); } @@ -88,7 +88,7 @@ function verify($pw,$hash) { if ($len!=strlen($hash) || $len<14) return FALSE; $out=0; - for ($i=0;$i<$len;$i++) + for ($i=0;$i<$len;++$i) $out|=(ord($val[$i])^ord($hash[$i])); return $out===0; } diff --git a/cli/ws.php b/cli/ws.php index f1573c01..4545e9bc 100644 --- a/cli/ws.php +++ b/cli/ws.php @@ -424,16 +424,16 @@ function fetch() { } else if ($len==0x7f) { - for ($i=0,$len=0;$i<8;$i++) + for ($i=0,$len=0;$i<8;++$i) $len=$len*256+ord($buf[$i+2]); $pos+=8; } - for ($i=0,$mask=[];$i<4;$i++) + for ($i=0,$mask=[];$i<4;++$i) $mask[$i]=ord($buf[$pos+$i]); $pos+=4; if (strlen($buf)<$len+$pos) return FALSE; - for ($i=0,$data='';$i<$len;$i++) + for ($i=0,$data='';$i<$len;++$i) $data.=chr(ord($buf[$pos+$i])^$mask[$i%4]); // Dispatch switch ($op & WS::OpCode) { diff --git a/db/jig/mapper.php b/db/jig/mapper.php index 784b2a8f..5d26427f 100644 --- a/db/jig/mapper.php +++ b/db/jig/mapper.php @@ -206,7 +206,7 @@ function($_row) use($fw,$args,$tokens) { if (is_string($token)) if ($token=='?') { // Positional - $ctr++; + ++$ctr; $key=$ctr; } else { diff --git a/db/sql.php b/db/sql.php index d64db8ac..02bd3841 100644 --- a/db/sql.php +++ b/db/sql.php @@ -173,7 +173,7 @@ function exec($cmds,$args=NULL,$ttl=0,$log=TRUE,$stamp=FALSE) { $fw=\Base::instance(); $cache=\Cache::instance(); $result=FALSE; - for ($i=0;$i<$count;$i++) { + for ($i=0;$i<$count;++$i) { $cmd=$cmds[$i]; $arg=$args[$i]; // ensure 1-based arguments diff --git a/db/sql/mapper.php b/db/sql/mapper.php index 59e399fb..574cc9fb 100644 --- a/db/sql/mapper.php +++ b/db/sql/mapper.php @@ -458,13 +458,13 @@ function insert() { $inc=$key; $filter.=($filter?' AND ':'').$this->db->quotekey($key).'=?'; $nkeys[$nctr+1]=[$field['value'],$field['pdo_type']]; - $nctr++; + ++$nctr; } if ($field['changed'] && $key!=$inc) { $fields.=($actr?',':'').$this->db->quotekey($key); $values.=($actr?',':'').'?'; $args[$actr+1]=[$field['value'],$field['pdo_type']]; - $actr++; + ++$actr; $ckeys[]=$key; } unset($field); @@ -623,7 +623,7 @@ function erase($filter=NULL,$quick=TRUE) { $filter.=($filter?' AND ':'').$this->db->quotekey($key).'=?'; $args[$ctr+1]=[$field['previous'],$field['pdo_type']]; $pkeys[$key]=$field['previous']; - $ctr++; + ++$ctr; } $field['value']=NULL; $field['changed']=(bool)$field['default']; diff --git a/image.php b/image.php index 59c165eb..b7f149ce 100644 --- a/image.php +++ b/image.php @@ -367,15 +367,15 @@ function identicon($str,$size=64,$blocks=4) { imagefill($this->data,0,0,IMG_COLOR_TRANSPARENT); $ctr=count($sprites); $dim=$blocks*floor($size/$blocks)*2/$blocks; - for ($j=0,$y=ceil($blocks/2);$j<$y;$j++) - for ($i=$j,$x=$blocks-1-$j;$i<$x;$i++) { + for ($j=0,$y=ceil($blocks/2);$j<$y;++$j) + for ($i=$j,$x=$blocks-1-$j;$i<$x;++$i) { $sprite=imagecreatetruecolor($dim,$dim); imagefill($sprite,0,0,IMG_COLOR_TRANSPARENT); $block=$sprites[hexdec($hash[($j*$blocks+$i)*2])%$ctr]; - for ($k=0,$pts=count($block);$k<$pts;$k++) + for ($k=0,$pts=count($block);$k<$pts;++$k) $block[$k]*=$dim; imagefilledpolygon($sprite,$block,$pts/2,$fg); - for ($k=0;$k<4;$k++) { + for ($k=0;$k<4;++$k) { imagecopyresampled($this->data,$sprite, $i*$dim/2,$j*$dim/2,0,0,$dim/2,$dim/2,$dim,$dim); $this->data=imagerotate($this->data,90, @@ -416,7 +416,7 @@ function captcha($font,$size=24,$len=5, -$len)); $block=$size*3; $tmp=[]; - for ($i=0,$width=0,$height=0;$i<$len;$i++) { + for ($i=0,$width=0,$height=0;$i<$len;++$i) { // Process at 2x magnification $box=imagettfbbox($size*2,0,$path,$seed[$i]); $w=$box[2]-$box[0]; @@ -440,7 +440,7 @@ function captcha($font,$size=24,$len=5, } $this->data=imagecreatetruecolor($width,$height); imagefill($this->data,0,0,IMG_COLOR_TRANSPARENT); - for ($i=0;$i<$len;$i++) { + for ($i=0;$i<$len;++$i) { imagecopy($this->data,$tmp[$i], $i*$block/2,($height-imagesy($tmp[$i]))/2,0,0, imagesx($tmp[$i]),imagesy($tmp[$i])); @@ -520,7 +520,7 @@ function save() { if ($this->flag) { if (!is_dir($dir=$fw->TEMP)) mkdir($dir,Base::MODE,TRUE); - $this->count++; + ++$this->count; $fw->write($dir.'/'.$fw->SEED.'.'. $fw->hash($this->file).'-'.$this->count.'.png', $this->dump()); diff --git a/matrix.php b/matrix.php index d1f00877..6c22bae2 100644 --- a/matrix.php +++ b/matrix.php @@ -130,7 +130,7 @@ function calendar($date='now',$first=0) { $days=cal_days_in_month(CAL_GREGORIAN,$parts['mon'],$parts['year']); $ref=date('w',strtotime(date('Y-m',$parts[0]).'-01'))+(7-$first)%7; $out=[]; - for ($i=0;$i<$days;$i++) + for ($i=0;$i<$days;++$i) $out[floor(($ref+$i)/7)][($ref+$i)%7]=$i+1; } return $out; diff --git a/template.php b/template.php index 8e744a99..d73f1a83 100644 --- a/template.php +++ b/template.php @@ -326,7 +326,7 @@ function parse($text) { $tmp.=substr($text,$ptr,$w); $ptr+=$w; if ($w<50) - $w++; + ++$w; } if (strlen($tmp)) // Append trailing text diff --git a/web.php b/web.php index 05aecac7..df73ecf7 100644 --- a/web.php +++ b/web.php @@ -230,7 +230,7 @@ function send($file,$mime=NULL,$kbps=0,$force=TRUE,$name=NULL,$flush=TRUE) { !$info['timed_out'] && !connection_aborted()) { if ($kbps) { // Throttle output - $ctr++; + ++$ctr; if ($ctr/$kbps>$elapsed=microtime(TRUE)-$start) usleep(1e6*($ctr/$kbps-$elapsed)); } @@ -751,13 +751,13 @@ function minify($files,$mime=NULL,$header=TRUE,$path=NULL) { '/(return|[(:=!+\-*&|])$/', substr($src,0,$ofs))) { $data.='/'; - $ptr++; + ++$ptr; while ($ptr<$len) { $data.=$src[$ptr]; - $ptr++; + ++$ptr; if ($src[$ptr-1]=='\\') { $data.=$src[$ptr]; - $ptr++; + ++$ptr; } elseif ($src[$ptr-1]=='/') break; @@ -773,7 +773,7 @@ function minify($files,$mime=NULL,$header=TRUE,$path=NULL) { if (!$regex) { // Division operator $data.=$src[$ptr]; - $ptr++; + ++$ptr; } } continue; @@ -781,14 +781,14 @@ function minify($files,$mime=NULL,$header=TRUE,$path=NULL) { if (in_array($src[$ptr],['\'','"','`'])) { $match=$src[$ptr]; $data.=$match; - $ptr++; + ++$ptr; // String literal while ($ptr<$len) { $data.=$src[$ptr]; - $ptr++; + ++$ptr; if ($src[$ptr-1]=='\\') { $data.=$src[$ptr]; - $ptr++; + ++$ptr; } elseif ($src[$ptr-1]==$match) break; @@ -804,11 +804,11 @@ function minify($files,$mime=NULL,$header=TRUE,$path=NULL) { ($ext[0]=='css' && $ptr+2channel)) { $out['source']=(string)$xml->channel->title; $max=min($max,count($xml->channel->item)); - for ($i=0;$i<$max;$i++) { + for ($i=0;$i<$max;++$i) { $item=$xml->channel->item[$i]; $list=[''=>NULL]+$item->getnamespaces(TRUE); $fields=[]; @@ -984,7 +984,7 @@ function filler($count=1,$max=20,$std=TRUE) { 'repudiandae rerum saepe sapiente sequi similique sint soluta '. 'suscipit tempora tenetur totam ut ullam unde vel veniam vero '. 'vitae voluptas'); - for ($i=0,$add=$count-(int)$std;$i<$add;$i++) { + for ($i=0,$add=$count-(int)$std;$i<$add;++$i) { shuffle($rnd); $words=array_slice($rnd,0,mt_rand(3,$max)); $out.=(!$std&&$i==0?'':' ').ucfirst(implode(' ',$words)).'.'; diff --git a/web/openid.php b/web/openid.php index c940af32..6e84b612 100644 --- a/web/openid.php +++ b/web/openid.php @@ -103,7 +103,7 @@ protected function discover($proxy) { $ptr+=strlen($parts[0]); } else - $ptr++; + ++$ptr; } // Get OpenID provider's endpoint URL if (isset($this->args['provider'])) {