From: Rico Tzschichholz Date: Sun, 13 Oct 2019 19:08:43 +0000 (+0200) Subject: codegen: Replace if-else-tree with switch in CCodeBaseModule.visit_binary_expression() X-Git-Tag: 0.47.1~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7db6bc984027c1cafe1c3e2872918a6b48962271;p=thirdparty%2Fvala.git codegen: Replace if-else-tree with switch in CCodeBaseModule.visit_binary_expression() --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 5ea9b6183..83f028013 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -5456,7 +5456,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { && expr.left.value_type.compatible (string_type) && !(expr.right.value_type is NullType) && expr.right.value_type.compatible (string_type)) { - if (expr.operator == BinaryOperator.PLUS) { + switch (expr.operator) { + case BinaryOperator.PLUS: // string concatenation if (expr.left.is_constant () && expr.right.is_constant ()) { string left, right; @@ -5479,7 +5480,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } set_cvalue (expr, new CCodeConstant ("%s %s".printf (left, right))); - return; } else { var temp_value = create_temp_value (expr.value_type, false, expr); CCodeFunctionCall ccall; @@ -5513,14 +5513,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ccode.add_assignment (get_cvalue_ (temp_value), ccall); expr.target_value = temp_value; - return; } - } else if (expr.operator == BinaryOperator.EQUALITY - || expr.operator == BinaryOperator.INEQUALITY - || expr.operator == BinaryOperator.LESS_THAN - || expr.operator == BinaryOperator.GREATER_THAN - || expr.operator == BinaryOperator.LESS_THAN_OR_EQUAL - || expr.operator == BinaryOperator.GREATER_THAN_OR_EQUAL) { + return; + case BinaryOperator.EQUALITY: + case BinaryOperator.INEQUALITY: + case BinaryOperator.LESS_THAN: + case BinaryOperator.GREATER_THAN: + case BinaryOperator.LESS_THAN_OR_EQUAL: + case BinaryOperator.GREATER_THAN_OR_EQUAL: CCodeFunctionCall ccall; if (context.profile == Profile.POSIX) { ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_cmp_wrapper (new CCodeIdentifier ("strcmp")))); @@ -5531,6 +5531,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ccall.add_argument (cright); cleft = ccall; cright = new CCodeConstant ("0"); + break; + default: + break; } }