Skip to content

Commit

Permalink
cgen: reduce expense in repetitively called functions by using consts (
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Nov 2, 2023
1 parent 1e80e47 commit eb74856
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions vlib/v/gen/c/fn.v
Expand Up @@ -7,6 +7,8 @@ import strings
import v.ast
import v.util

const c_fn_name_escape_seq = ['[', '_T_', ']', '']

fn (mut g Gen) is_used_by_main(node ast.FnDecl) bool {
mut is_used_by_main := true
if g.pref.skip_unused {
Expand Down Expand Up @@ -449,7 +451,7 @@ fn (mut g Gen) c_fn_name(node &ast.FnDecl) string {
unwrapped_rec_typ := g.unwrap_generic(node.receiver.typ)
name = g.cc_type(unwrapped_rec_typ, false) + '_' + name
if g.table.sym(unwrapped_rec_typ).kind == .placeholder {
name = name.replace_each(['[', '_T_', ']', ''])
name = name.replace_each(c.c_fn_name_escape_seq)
}
}
if node.language == .c {
Expand Down Expand Up @@ -613,7 +615,7 @@ fn (mut g Gen) fn_decl_params(params []ast.Param, scope &ast.Scope, is_variadic
typ = g.table.sym(typ).array_info().elem_type.set_flag(.variadic)
}
param_type_sym := g.table.sym(typ)
mut param_type_name := g.typ(typ).replace_each(['[', '_T_', ']', ''])
mut param_type_name := g.typ(typ).replace_each(c.c_fn_name_escape_seq)
if param_type_sym.kind == .function && !typ.has_flag(.option) {
info := param_type_sym.info as ast.FnType
func := info.func
Expand Down

0 comments on commit eb74856

Please sign in to comment.