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

@ -904,8 +904,10 @@ class Artists implements Extension {
, array(
$artistID
));
for ($i = 0 ; $i < count($result) ; $i++)
$num = count($result);
for ($i = 0 ; $i < $num ; $i++)
{
$result[$i]["name"] = stripslashes($result[$i]["name"]);
}
@ -921,8 +923,10 @@ class Artists implements Extension {
, array(
$artistID
));
$num = count($result);
for ($i = 0 ; $i < count($result) ; $i++)
for ($i = 0 ; $i < $num ; $i++)
{
$result[$i]["url"] = stripslashes($result[$i]["url"]);
}
@ -1038,8 +1042,10 @@ class Artists implements Extension {
$pageNumber * $artistsPerPage
, $artistsPerPage
));
$number_of_listings = count($listing);
for ($i = 0 ; $i < count($listing) ; $i++)
for ($i = 0 ; $i < $number_of_listings ; $i++)
{
$listing[$i]["name"] = stripslashes($listing[$i]["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.
$table_rows = "";
for ($i = 0 ; $i < count($entries) ; $i++)
$num_entries = count($entries);
for ($i = 0 ; $i < $num_entries ; $i++)
{
/**
* Add table rows
@ -106,7 +107,8 @@ class BlotterTheme extends Themelet {
$html .= "<html><head><title>Blotter</title></head>
<body><pre>";
for ($i = 0 ; $i < count($entries) ; $i++)
$num_entries = count($entries);
for ($i = 0 ; $i < $num_entries ; $i++)
{
/**
* Blotter entries
@ -156,7 +158,8 @@ $(document).ready(function() {
});
//--></script>";
$entries_list = "";
for ($i = 0 ; $i < count($entries) ; $i++)
$num_entries = count($entries);
for ($i = 0 ; $i < $num_entries ; $i++)
{
/**
* Blotter entries
@ -175,8 +178,8 @@ $(document).ready(function() {
$in_text = "";
$pos_break = "";
$pos_align = "text-align: right; position: absolute; right: 0px;";
if($position == "left") { $pos_break = "<br />"; $pos_align = ""; }
if(count($entries) == 0) { $out_text = "No blotter entries yet."; $in_text = "Empty.";}
if($position === "left") { $pos_break = "<br />"; $pos_align = ""; }
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']));
$out_text = "Blotter updated: {$clean_date}";
$in_text = "<ul>$entries_list</ul>";

View File

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

View File

@ -69,7 +69,8 @@ class Home extends SimpleExtension {
$num_comma = number_format($total);
$counter_text = "";
for($n=0; $n<strlen($strtotal); $n++) {
$length = strlen($strtotal);
for($n=0; $n<$length; $n++) {
$cur = $strtotal[$n];
$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)) {
$sqes = $matches[1];
$arr = array();
for($i=0; $i<strlen($sqes); $i++) {
$length = strlen($sqes);
for($i=0; $i<$length; $i++) {
$arr[] = "'" . $sqes[$i] . "'";
}
$set = join(', ', $arr);
@ -150,7 +151,8 @@ class Ratings implements Extension {
public static function privs_to_sql($sqes) {
$arr = array();
for($i=0; $i<strlen($sqes); $i++) {
$length = strlen($sqes);
for($i=0; $i<$length; $i++) {
$arr[] = "'" . $sqes[$i] . "'";
}
$set = join(', ', $arr);

View File

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

View File

@ -114,7 +114,7 @@ class CommentList extends SimpleExtension {
public function onPageRequest(PageRequestEvent $event) {
global $page, $user;
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'])) {
try {
$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()) {
// FIXME: post, not args
if($event->count_args() == 3) {
if($event->count_args() === 3) {
send_event(new CommentDeletionEvent($event->get_arg(1)));
$page->set_mode("redirect");
if(!empty($_SERVER['HTTP_REFERER'])) {
@ -145,7 +145,7 @@ class CommentList extends SimpleExtension {
$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));
}
}
@ -367,7 +367,7 @@ class CommentList extends SimpleExtension {
global $database;
// 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'));
$max = int_escape($config->get_int('comment_limit'));

View File

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

View File

@ -15,7 +15,9 @@ class UploadTheme extends Themelet {
// Uploader 2.0!
$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;
$s=$i-1;
@ -244,7 +246,9 @@ class UploadTheme extends Themelet {
global $config;
$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'";
else $style = "style='display:none'";
$upload_list .= "<input size='10' ".

View File

@ -904,7 +904,9 @@ class Securimage {
}
$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
$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(' '));