Skip to content

Commit

Permalink
Dev: optimization of EM core during replacement
Browse files Browse the repository at this point in the history
Dev: break recursion if no update of result
  • Loading branch information
Shnoulle committed Mar 24, 2018
1 parent 1560b9c commit 9ecd0ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 22 additions & 1 deletion application/helpers/expressions/em_core_helper.php
Expand Up @@ -1668,11 +1668,22 @@ public function sProcessStringContainingExpressions($src, $questionNum = 0, $num
$prettyPrint = '';
$errors = array();

$prettyPrintIterationDone = false;
for ($i = 1; $i <= $numRecursionLevels; ++$i) {
// TODO - Since want to use <span> for dynamic substitution, what if there are recursive substititons?
$prevResult = $result;
$result = $this->sProcessStringContainingExpressionsHelper($result, $questionNum, $staticReplacement);
if($result === $prevResult) {
// No update during process : can exit of iteration
if(!$prettyPrintIterationDone) {
$prettyPrint = $this->prettyPrintSource;
}
// No need errors : already done
break;
}
if ($i == $whichPrettyPrintIteration) {
$prettyPrint = $this->prettyPrintSource;
$prettyPrintIterationDone = true;
}
$errors = array_merge($errors, $this->RDP_errs);
}
Expand Down Expand Up @@ -1962,10 +1973,20 @@ private function RDP_SetVariableValue($op, $name, $value)
*/
public function asSplitStringOnExpressions($src)
{
// Empty string, return an array
if($src === "") {
return array();
}
// No replacement to do, preg_split get more time than strpos
if(strpos($src, "{") === false || $src==="{" || $src==="}") {
return array (
0 => array ($src,0,'STRING')
);
};

// Seems to need split and replacement
$parts = preg_split($this->RDP_ExpressionRegex, $src, -1, (PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE));


$count = count($parts);
$tokens = array();
$inSQString = false;
Expand Down
2 changes: 2 additions & 0 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -347,12 +347,14 @@ class LimeExpressionManager {
* current Group sequence (0-based index)
* @example 1
* @var integer
* @deprecated : not updated in this class

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Mar 26, 2018

Author Collaborator

Sorry , serach this->currentQuestionSeq , not LEM->currentQuestionSeq

*/
private $currentGroupSeq;
/**
* for Question-by-Question mode, the 0-based index
* @example 3
* @var integer
* @deprecated : not updated in this class
*/
private $currentQuestionSeq;
/**
Expand Down

0 comments on commit 9ecd0ab

Please sign in to comment.