gen: minor optimization in `type_to_fmt()` (#7028)
parent
f7cc3d3718
commit
39b46e95a0
|
@ -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 {
|
fn (g &Gen) type_to_fmt(typ table.Type) string {
|
||||||
sym := g.table.get_type_symbol(typ)
|
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'
|
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'
|
return '%.*s\\000'
|
||||||
} else if sym.kind == .string {
|
} else if sym.kind == .string {
|
||||||
return "\'%.*s\\000\'"
|
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] {
|
} else if sym.kind in [.f32, .f64] {
|
||||||
return '%g\\000' // g removes trailing zeros unlike %f
|
return '%g\\000' // g removes trailing zeros unlike %f
|
||||||
} else if sym.kind == .u64 {
|
} else if sym.kind == .u64 {
|
||||||
return '%lld\\000'
|
return '%lld\\000'
|
||||||
} else if sym.kind == .sum_type {
|
|
||||||
return '%.*s\\000'
|
|
||||||
}
|
}
|
||||||
return '%d\\000'
|
return '%d\\000'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue