Changing for-loops to use pre-calculated values.

Rather than calculating the value each time.
This commit is contained in:
green-ponies (jgen) 2012-01-16 00:07:04 -05:00
parent 8252534cff
commit cd7de93a0a
10 changed files with 44 additions and 23 deletions

View File

@ -905,7 +905,9 @@ class Artists implements Extension {
$artistID $artistID
)); ));
for ($i = 0 ; $i < count($result) ; $i++) $num = count($result);
for ($i = 0 ; $i < $num ; $i++)
{ {
$result[$i]["name"] = stripslashes($result[$i]["name"]); $result[$i]["name"] = stripslashes($result[$i]["name"]);
} }
@ -922,7 +924,9 @@ class Artists implements Extension {
$artistID $artistID
)); ));
for ($i = 0 ; $i < count($result) ; $i++) $num = count($result);
for ($i = 0 ; $i < $num ; $i++)
{ {
$result[$i]["url"] = stripslashes($result[$i]["url"]); $result[$i]["url"] = stripslashes($result[$i]["url"]);
} }
@ -1039,7 +1043,9 @@ class Artists implements Extension {
, $artistsPerPage , $artistsPerPage
)); ));
for ($i = 0 ; $i < count($listing) ; $i++) $number_of_listings = count($listing);
for ($i = 0 ; $i < $number_of_listings ; $i++)
{ {
$listing[$i]["name"] = stripslashes($listing[$i]["name"]); $listing[$i]["name"] = stripslashes($listing[$i]["name"]);
$listing[$i]["user_name"] = stripslashes($listing[$i]["user_name"]); $listing[$i]["user_name"] = stripslashes($listing[$i]["user_name"]);

View File

@ -55,7 +55,8 @@ class BlotterTheme extends Themelet {
// Now, time for entries list. // Now, time for entries list.
$table_rows = ""; $table_rows = "";
for ($i = 0 ; $i < count($entries) ; $i++) $num_entries = count($entries);
for ($i = 0 ; $i < $num_entries ; $i++)
{ {
/** /**
* Add table rows * Add table rows
@ -106,7 +107,8 @@ class BlotterTheme extends Themelet {
$html .= "<html><head><title>Blotter</title></head> $html .= "<html><head><title>Blotter</title></head>
<body><pre>"; <body><pre>";
for ($i = 0 ; $i < count($entries) ; $i++) $num_entries = count($entries);
for ($i = 0 ; $i < $num_entries ; $i++)
{ {
/** /**
* Blotter entries * Blotter entries
@ -156,7 +158,8 @@ $(document).ready(function() {
}); });
//--></script>"; //--></script>";
$entries_list = ""; $entries_list = "";
for ($i = 0 ; $i < count($entries) ; $i++) $num_entries = count($entries);
for ($i = 0 ; $i < $num_entries ; $i++)
{ {
/** /**
* Blotter entries * Blotter entries
@ -175,8 +178,8 @@ $(document).ready(function() {
$in_text = ""; $in_text = "";
$pos_break = ""; $pos_break = "";
$pos_align = "text-align: right; position: absolute; right: 0px;"; $pos_align = "text-align: right; position: absolute; right: 0px;";
if($position == "left") { $pos_break = "<br />"; $pos_align = ""; } if($position === "left") { $pos_break = "<br />"; $pos_align = ""; }
if(count($entries) == 0) { $out_text = "No blotter entries yet."; $in_text = "Empty.";} if(count($entries) === 0) { $out_text = "No blotter entries yet."; $in_text = "Empty.";}
else { $clean_date = date("m/d/y",strtotime($entries[0]['entry_date'])); else { $clean_date = date("m/d/y",strtotime($entries[0]['entry_date']));
$out_text = "Blotter updated: {$clean_date}"; $out_text = "Blotter updated: {$clean_date}";
$in_text = "<ul>$entries_list</ul>"; $in_text = "<ul>$entries_list</ul>";

View File

@ -56,7 +56,8 @@ class FlashFileHandler extends DataHandlerExtension {
private function str_to_binarray($string) { private function str_to_binarray($string) {
$binary = array(); $binary = array();
for($j=0; $j<strlen($string); $j++) { $length = strlen($string);
for($j=0; $j<$length; $j++) {
$c = ord($string[$j]); $c = ord($string[$j]);
for($i=7; $i>=0; $i--) { for($i=7; $i>=0; $i--) {
$binary[] = ($c >> $i) & 0x01; $binary[] = ($c >> $i) & 0x01;

View File

@ -69,7 +69,8 @@ class Home extends SimpleExtension {
$num_comma = number_format($total); $num_comma = number_format($total);
$counter_text = ""; $counter_text = "";
for($n=0; $n<strlen($strtotal); $n++) { $length = strlen($strtotal);
for($n=0; $n<$length; $n++) {
$cur = $strtotal[$n]; $cur = $strtotal[$n];
$counter_text .= " <img alt='$cur' src='$data_href/ext/home/counters/$counter_dir/$cur.gif' /> "; $counter_text .= " <img alt='$cur' src='$data_href/ext/home/counters/$counter_dir/$cur.gif' /> ";
} }

View File

@ -107,7 +107,8 @@ class Ratings implements Extension {
if(preg_match("/^rating=([sqeu]+)$/", $event->term, $matches)) { if(preg_match("/^rating=([sqeu]+)$/", $event->term, $matches)) {
$sqes = $matches[1]; $sqes = $matches[1];
$arr = array(); $arr = array();
for($i=0; $i<strlen($sqes); $i++) { $length = strlen($sqes);
for($i=0; $i<$length; $i++) {
$arr[] = "'" . $sqes[$i] . "'"; $arr[] = "'" . $sqes[$i] . "'";
} }
$set = join(', ', $arr); $set = join(', ', $arr);
@ -150,7 +151,8 @@ class Ratings implements Extension {
public static function privs_to_sql($sqes) { public static function privs_to_sql($sqes) {
$arr = array(); $arr = array();
for($i=0; $i<strlen($sqes); $i++) { $length = strlen($sqes);
for($i=0; $i<$length; $i++) {
$arr[] = "'" . $sqes[$i] . "'"; $arr[] = "'" . $sqes[$i] . "'";
} }
$set = join(', ', $arr); $set = join(', ', $arr);

View File

@ -906,7 +906,8 @@ function _sanitise_environment() {
*/ */
function _decaret($str) { function _decaret($str) {
$out = ""; $out = "";
for($i=0; $i<strlen($str); $i++) { $length = strlen($str);
for($i=0; $i<$length; $i++) {
if($str[$i] == "^") { if($str[$i] == "^") {
$i++; $i++;
if($str[$i] == "^") $out .= "^"; if($str[$i] == "^") $out .= "^";

View File

@ -114,7 +114,7 @@ class CommentList extends SimpleExtension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page, $user; global $page, $user;
if($event->page_matches("comment")) { if($event->page_matches("comment")) {
if($event->get_arg(0) == "add") { if($event->get_arg(0) === "add") {
if(isset($_POST['image_id']) && isset($_POST['comment'])) { if(isset($_POST['image_id']) && isset($_POST['comment'])) {
try { try {
$cpe = new CommentPostingEvent($_POST['image_id'], $user, $_POST['comment']); $cpe = new CommentPostingEvent($_POST['image_id'], $user, $_POST['comment']);
@ -127,10 +127,10 @@ class CommentList extends SimpleExtension {
} }
} }
} }
else if($event->get_arg(0) == "delete") { else if($event->get_arg(0) === "delete") {
if($user->is_admin()) { if($user->is_admin()) {
// FIXME: post, not args // FIXME: post, not args
if($event->count_args() == 3) { if($event->count_args() === 3) {
send_event(new CommentDeletionEvent($event->get_arg(1))); send_event(new CommentDeletionEvent($event->get_arg(1)));
$page->set_mode("redirect"); $page->set_mode("redirect");
if(!empty($_SERVER['HTTP_REFERER'])) { if(!empty($_SERVER['HTTP_REFERER'])) {
@ -145,7 +145,7 @@ class CommentList extends SimpleExtension {
$this->theme->display_permission_denied($page); $this->theme->display_permission_denied($page);
} }
} }
else if($event->get_arg(0) == "list") { else if($event->get_arg(0) === "list") {
$this->build_page($event->get_arg(1)); $this->build_page($event->get_arg(1));
} }
} }
@ -367,7 +367,7 @@ class CommentList extends SimpleExtension {
global $database; global $database;
// sqlite fails at intervals // sqlite fails at intervals
if($database->engine->name == "sqlite") return false; if($database->engine->name === "sqlite") return false;
$window = int_escape($config->get_int('comment_window')); $window = int_escape($config->get_int('comment_window'));
$max = int_escape($config->get_int('comment_limit')); $max = int_escape($config->get_int('comment_limit'));

View File

@ -25,12 +25,13 @@ class ExtensionInfo {
function ExtensionInfo($main) { function ExtensionInfo($main) {
$matches = array(); $matches = array();
$lines = file($main); $lines = file($main);
$number_of_lines = count($lines);
preg_match("#(ext|contrib)/(.*)/main.php#", $main, $matches); preg_match("#(ext|contrib)/(.*)/main.php#", $main, $matches);
$this->ext_name = $matches[2]; $this->ext_name = $matches[2];
$this->name = $this->ext_name; $this->name = $this->ext_name;
$this->enabled = $this->is_enabled($this->ext_name); $this->enabled = $this->is_enabled($this->ext_name);
for($i=0; $i<count($lines); $i++) { for($i=0; $i<$number_of_lines; $i++) {
$line = $lines[$i]; $line = $lines[$i];
if(preg_match("/Name: (.*)/", $line, $matches)) { if(preg_match("/Name: (.*)/", $line, $matches)) {
$this->name = $matches[1]; $this->name = $matches[1];

View File

@ -15,7 +15,9 @@ class UploadTheme extends Themelet {
// Uploader 2.0! // Uploader 2.0!
$upload_list = ""; $upload_list = "";
for($i=0; $i<$config->get_int('upload_count'); $i++) $upload_count = $config->get_int('upload_count');
for($i=0; $i<$upload_count; $i++)
{ {
$a=$i+1; $a=$i+1;
$s=$i-1; $s=$i-1;
@ -244,7 +246,9 @@ class UploadTheme extends Themelet {
global $config; global $config;
$upload_list = ""; $upload_list = "";
for($i=0; $i<$config->get_int('upload_count'); $i++) { $upload_count = $config->get_int('upload_count');
for($i=0; $i<$upload_count; $i++) {
if($i == 0) $style = ""; // "style='display:visible'"; if($i == 0) $style = ""; // "style='display:visible'";
else $style = "style='display:none'"; else $style = "style='display:none'";
$upload_list .= "<input size='10' ". $upload_list .= "<input size='10' ".

View File

@ -904,7 +904,9 @@ class Securimage {
} }
$out_data = ''; $out_data = '';
for($i = 0; $i < sizeof($files); ++$i) { $file_size = sizeof($files);
for($i = 0; $i < $file_size; ++$i) {
if ($i == 0) { // output header if ($i == 0) { // output header
$out_data .= pack('C4VC8', ord('R'), ord('I'), ord('F'), ord('F'), $data_len + 36, ord('W'), ord('A'), ord('V'), ord('E'), ord('f'), ord('m'), ord('t'), ord(' ')); $out_data .= pack('C4VC8', ord('R'), ord('I'), ord('F'), ord('F'), $data_len + 36, ord('W'), ord('A'), ord('V'), ord('E'), ord('f'), ord('m'), ord('t'), ord(' '));