Skip to content

Commit 59522c5

Browse files
committed
Generate less code in compile time binary op test
Don't generate try {} blocks for the operations that don't throw.
1 parent 7acc828 commit 59522c5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Zend/tests/runtime_compile_time_binary_operands.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,16 @@ function prepareLine($op1, $op2, $cmp, $operator) {
108108
$error = "echo '" . addcslashes("$op1_p $operator $op2_p", "\\'") . '\', "\n"; $f++;';
109109

110110
$compare = "@($op1_p $operator $op2_p)";
111-
$line = "\$c++; try { ";
111+
$line = "\$c++; ";
112112
try {
113113
$result = makeParam($cmp());
114-
$line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error } } catch (Error \$e) { $error }";
114+
$line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error }";
115115
} catch (Error $e) {
116116
if (get_class($e) == "Error") {
117117
return "// exempt $op1_p $operator $op2_p from checking, it generates a compile time error";
118118
}
119119
$msg = makeParam($e->getMessage());
120-
$line .= "$compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
120+
$line .= "try { $compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
121121
}
122122
return $line;
123123
}
@@ -130,7 +130,10 @@ fwrite($file, "<?php\n");
130130
foreach ($input as $left) {
131131
foreach ($input as $right) {
132132
foreach ($operands as $operand) {
133-
fwrite($file, prepareLine($left, $right, function() use ($left, $right, $operand) { return eval("return @(\$left $operand \$right);"); }, $operand) . "\n");
133+
$line = prepareLine($left, $right, function() use ($left, $right, $operand) {
134+
return eval("return @(\$left $operand \$right);");
135+
}, $operand);
136+
fwrite($file, $line . "\n");
134137
}
135138
}
136139
}

0 commit comments

Comments
 (0)