From 39b46e95a0fd317f01de7ea314b5d0ffe1a68eab Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 30 Nov 2020 15:35:55 +0800 Subject: [PATCH] gen: minor optimization in `type_to_fmt()` (#7028) --- vlib/v/gen/cgen.v | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 616a5d92b9..cbd47867de 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -5563,22 +5563,16 @@ fn (mut g Gen) gen_str_default(sym table.TypeSymbol, styp string, str_fn_name st fn (g &Gen) type_to_fmt(typ table.Type) string { sym := g.table.get_type_symbol(typ) - if (typ.is_int() || typ.is_float()) && typ.is_ptr() { + if typ.is_ptr() && (typ.is_int() || typ.is_float()) { return '%.*s\\000' - } else if sym.kind in [.struct_, .array, .array_fixed, .map] { + } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .sum_type] { return '%.*s\\000' } else if sym.kind == .string { return "\'%.*s\\000\'" - } else if sym.kind == .bool { - return '%.*s\\000' - } else if sym.kind == .enum_ { - return '%.*s\\000' } else if sym.kind in [.f32, .f64] { return '%g\\000' // g removes trailing zeros unlike %f } else if sym.kind == .u64 { return '%lld\\000' - } else if sym.kind == .sum_type { - return '%.*s\\000' } return '%d\\000' }