Skip to content

Commit

Permalink
Performance MDL-25637 moved static count/sizeof functions out of for …
Browse files Browse the repository at this point in the history
…loop conditions
  • Loading branch information
Aparup Banerjee committed Jan 24, 2011
1 parent f179cdb commit b692e4a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 19 deletions.
13 changes: 7 additions & 6 deletions auth/shibboleth/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ function LogoutNotification($SessionID){
/*****************************************************************************/

// Same function as in adodb, but cannot be used for file session for some reason...
function unserializesession( $serialized_string ){
$variables = array( );
$a = preg_split( "/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
for( $i = 0; $i < count( $a ); $i = $i+2 ) {
$variables[$a[$i]] = unserialize( $a[$i+1] );
function unserializesession($serialized_string) {
$variables = array();
$a = preg_split("/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
$counta = count($a);
for($i = 0; $i < $counta; $i=$i+2) {
$variables[$a[$i]] = unserialize($a[$i+1]);
}
return( $variables );
return($variables);
}
6 changes: 4 additions & 2 deletions mod/feedback/item/info/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false
$data = $analysed_item->data;
if(is_array($data)) {
echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;('. $item->label .') ' . $item->name .'</th></tr>';
for($i = 0; $i < sizeof($data); $i++) {
$sizeofdata = sizeof($data);
for($i = 0; $i < $sizeofdata; $i++) {
echo '<tr><td colspan="2" valign="top" align="left">-&nbsp;&nbsp;' . str_replace("\n", '<br />', $data[$i]->show) . '</td></tr>';
}
}
Expand All @@ -148,7 +149,8 @@ function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid,
// $worksheet->setFormat("<l><ro2><vo>");
$worksheet->write_string($rowOffset, 2, $data[0]->show, $xlsFormats->value_bold);
$rowOffset++;
for($i = 1; $i < sizeof($data); $i++) {
$sizeofdata = sizeof($data);
for($i = 1; $i < $sizeofdata; $i++) {
// $worksheet->setFormat("<l><vo>");
$worksheet->write_string($rowOffset, 2, $data[$i]->show, $xlsFormats->default);
$rowOffset++;
Expand Down
9 changes: 6 additions & 3 deletions mod/feedback/item/multichoice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ function get_printval($item, $value) {
$vallist = array_values(explode (FEEDBACK_MULTICHOICE_LINE_SEP, $value->value));
$sizeofvallist = sizeof($vallist);
for($i = 0; $i < $sizeofvallist; $i++) {
for($k = 0; $k < sizeof($presentation); $k++) {
$sizeofpresentation = sizeof($presentation);
for($k = 0; $k < $sizeofpresentation; $k++) {
if($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0
$printval .= trim($presentation[$k]) . chr(10);
break;
Expand Down Expand Up @@ -235,7 +236,8 @@ function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid,
$worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2_green);
$worksheet->write_string($rowOffset, 1, $analysed_item[1], $xlsFormats->head2_green);
if(is_array($data)) {
for($i = 0; $i < sizeof($data); $i++) {
$sizeofdata = sizeof($data);
for($i = 0; $i < $sizeofdata; $i++) {
$aData = $data[$i];

// $worksheet->setFormat("<l><f><ro2><vo><c:blue>");
Expand Down Expand Up @@ -570,7 +572,8 @@ function item_arrayToString($value) {
$arrvals = array_values($value);
$arrvals = clean_param($arrvals, PARAM_INT); //prevent sql-injection
$retval = $arrvals[0];
for($i = 1; $i < sizeof($arrvals); $i++) {
$sizeofarrvals = sizeof($arrvals);
for($i = 1; $i < $sizeofarrvals; $i++) {
$retval .= FEEDBACK_MULTICHOICE_LINE_SEP.$arrvals[$i];
}
return $retval;
Expand Down
7 changes: 4 additions & 3 deletions mod/feedback/item/multichoicerated/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function get_analysed($item, $groupid = false, $courseid = false) {
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten

$analysedAnswer = array();

for($i = 1; $i <= sizeof($lines); $i++) {
$sizeoflines = sizeof($lines);
for($i = 1; $i <= $sizeoflines; $i++) {
$item_values = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $lines[$i-1]);
$ans = null;
$ans->answertext = $item_values[1];
Expand Down Expand Up @@ -215,7 +215,8 @@ function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid,
$worksheet->write_string($rowOffset, 1, $analysed_item[1], $xlsFormats->head2);
if(is_array($data)) {
$avg = 0.0;
for($i = 0; $i < sizeof($data); $i++) {
$sizeofdata = sizeof($data);
for($i = 0; $i < $sizeofdata; $i++) {
$aData = $data[$i];

// $worksheet->setFormat("<l><f><ro2><vo><c:blue>");
Expand Down
3 changes: 2 additions & 1 deletion mod/feedback/item/textarea/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid,
$worksheet->write_string($rowOffset, 2, $data[0], $xlsFormats->value_bold);
}
$rowOffset++;
for($i = 1; $i < sizeof($data); $i++) {
$sizeofdata = sizeof($data);
for($i = 1; $i < $sizeofdata; $i++) {
// $worksheet->setFormat("<l><vo>");
$worksheet->write_string($rowOffset, 2, $data[$i], $xlsFormats->default);
$rowOffset++;
Expand Down
3 changes: 2 additions & 1 deletion mod/feedback/item/textfield/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid,
// $worksheet->setFormat("<l><ro2><vo>");
$worksheet->write_string($rowOffset, 2, $data[0], $xlsFormats->value_bold);
$rowOffset++;
for($i = 1; $i < sizeof($data); $i++) {
$sizeofdata = sizeof($data);
for($i = 1; $i < $sizeofdata; $i++) {
// $worksheet->setFormat("<l><vo>");
$worksheet->write_string($rowOffset, 2, $data[$i], $xlsFormats->default);
$rowOffset++;
Expand Down
6 changes: 4 additions & 2 deletions question/format/blackboard_six/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ function clean_temp_dir($dir='') {
}

// Delete all files in the curent directory return false and halt if a file cannot be removed
for($i=0; $i<count($dir_files); $i++) {
$countdir_files = count($dir_files);
for($i=0; $i<$countdir_files; $i++) {
chmod($dir_files[$i], $CFG->directorypermissions);
if (((unlink($dir_files[$i]))) == FALSE) {
return false;
}
}

// Empty sub directories and then remove the directory
for($i=0; $i<count($dir_subdirs); $i++) {
$countdir_subdirs = count($dir_subdirs);
for($i=0; $i<$countdir_subdirs; $i++) {
chmod($dir_subdirs[$i], $CFG->directorypermissions);
if ($this->clean_temp_dir($dir_subdirs[$i]) == FALSE) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ function question_edit_calculatedsimple_form(&$submiturl, &$question, &$category
$calcmax = optional_param('calcmax', '', PARAM_NUMBER);
$oldoptions = optional_param('defoptions', '', PARAM_RAW);
$newdatasetvalues = false ;
for($key = 1 ; $key <= sizeof($olddef) ; $key++) {
$sizeofolddef = sizeof($olddef);
for($key = 1; $key <= $sizeofolddef; $key++) {
$def = $olddef[$key] ;
$this->datasetdefs[$def]= new stdClass ;
$this->datasetdefs[$def]->type = 1;
Expand Down

0 comments on commit b692e4a

Please sign in to comment.