]> granicus.if.org Git - php/commitdiff
Generate less code in compile time binary op test
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 1 Jul 2019 14:25:28 +0000 (16:25 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 1 Jul 2019 15:27:42 +0000 (17:27 +0200)
Don't generate try {} blocks for the operations that don't throw.

Zend/tests/runtime_compile_time_binary_operands.phpt

index 897ce3e1a5e52acb75a051cae0206df30e554103..afced7af0c866942acc5e5ecf250329ddabfc08d 100644 (file)
@@ -108,16 +108,16 @@ function prepareLine($op1, $op2, $cmp, $operator) {
        $error = "echo '" . addcslashes("$op1_p $operator $op2_p", "\\'") . '\', "\n"; $f++;';
 
        $compare = "@($op1_p $operator $op2_p)";
-       $line = "\$c++; try { ";
+       $line = "\$c++; ";
        try {
                $result = makeParam($cmp());
-               $line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error } } catch (Error \$e) { $error }";
+               $line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" : "$compare !== $result") . ") { $error }";
        } catch (Error $e) {
                if (get_class($e) == "Error") {
                        return "// exempt $op1_p $operator $op2_p from checking, it generates a compile time error";
                }
                $msg = makeParam($e->getMessage());
-               $line .= "$compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
+               $line .= "try { $compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error } }";
        }
        return $line;
 }
@@ -130,7 +130,10 @@ fwrite($file, "<?php\n");
 foreach ($input as $left) {
        foreach ($input as $right) {
                foreach ($operands as $operand) {
-                       fwrite($file, prepareLine($left, $right, function() use ($left, $right, $operand) { return eval("return @(\$left $operand \$right);"); }, $operand) . "\n");
+                       $line = prepareLine($left, $right, function() use ($left, $right, $operand) {
+                               return eval("return @(\$left $operand \$right);");
+                       }, $operand);
+                       fwrite($file, $line . "\n");
                }
        }
 }