Skip to content

Commit

Permalink
Moved increment operator to preceed variables rather than follow for …
Browse files Browse the repository at this point in the history
…speed improvements.
  • Loading branch information
Weshley authored and ikkez committed Nov 3, 2020
1 parent cd358aa commit 5f3b9d2
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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='';
Expand Down Expand Up @@ -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']))
Expand Down Expand Up @@ -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--;
Expand Down
4 changes: 2 additions & 2 deletions bcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions cli/ws.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion db/jig/mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function($_row) use($fw,$args,$tokens) {
if (is_string($token))
if ($token=='?') {
// Positional
$ctr++;
++$ctr;
$key=$ctr;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion db/sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions db/sql/mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'];
Expand Down
14 changes: 7 additions & 7 deletions image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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];
Expand All @@ -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]));
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
Expand All @@ -773,22 +773,22 @@ function minify($files,$mime=NULL,$header=TRUE,$path=NULL) {
if (!$regex) {
// Division operator
$data.=$src[$ptr];
$ptr++;
++$ptr;
}
}
continue;
}
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;
Expand All @@ -804,11 +804,11 @@ function minify($files,$mime=NULL,$header=TRUE,$path=NULL) {
($ext[0]=='css' && $ptr+2<strlen($src) &&
preg_match('/:\w/',substr($src,$ptr+1,2))))
$data.=' ';
$ptr++;
++$ptr;
continue;
}
$data.=$src[$ptr];
$ptr++;
++$ptr;
}
if ($ext[0]=='css')
$data=str_replace(';}','}',$data);
Expand Down Expand Up @@ -842,7 +842,7 @@ function rss($url,$max=10,$tags=NULL) {
if (isset($xml->channel)) {
$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=[];
Expand Down Expand Up @@ -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)).'.';
Expand Down
2 changes: 1 addition & 1 deletion web/openid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down

0 comments on commit 5f3b9d2

Please sign in to comment.