Skip to content

Commit eb74856

Browse files
authored
cgen: reduce expense in repetitively called functions by using consts (vlang#19732)
1 parent 1e80e47 commit eb74856

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

vlib/v/gen/c/fn.v

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import strings
77
import v.ast
88
import v.util
99

10+
const c_fn_name_escape_seq = ['[', '_T_', ']', '']
11+
1012
fn (mut g Gen) is_used_by_main(node ast.FnDecl) bool {
1113
mut is_used_by_main := true
1214
if g.pref.skip_unused {
@@ -449,7 +451,7 @@ fn (mut g Gen) c_fn_name(node &ast.FnDecl) string {
449451
unwrapped_rec_typ := g.unwrap_generic(node.receiver.typ)
450452
name = g.cc_type(unwrapped_rec_typ, false) + '_' + name
451453
if g.table.sym(unwrapped_rec_typ).kind == .placeholder {
452-
name = name.replace_each(['[', '_T_', ']', ''])
454+
name = name.replace_each(c.c_fn_name_escape_seq)
453455
}
454456
}
455457
if node.language == .c {
@@ -613,7 +615,7 @@ fn (mut g Gen) fn_decl_params(params []ast.Param, scope &ast.Scope, is_variadic
613615
typ = g.table.sym(typ).array_info().elem_type.set_flag(.variadic)
614616
}
615617
param_type_sym := g.table.sym(typ)
616-
mut param_type_name := g.typ(typ).replace_each(['[', '_T_', ']', ''])
618+
mut param_type_name := g.typ(typ).replace_each(c.c_fn_name_escape_seq)
617619
if param_type_sym.kind == .function && !typ.has_flag(.option) {
618620
info := param_type_sym.info as ast.FnType
619621
func := info.func

0 commit comments

Comments
 (0)