cgen: minor optimization of auto_eq_methods.v (#7668)

pull/7672/head
yuyi 2020-12-29 13:48:37 +08:00 committed by GitHub
parent 4d5ee0649c
commit b87283e970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -6,13 +6,13 @@ import strings
import v.table import v.table
fn (mut g Gen) gen_struct_equality_fn(left table.Type) string { fn (mut g Gen) gen_struct_equality_fn(left table.Type) string {
left_sym := g.table.get_type_symbol(left)
info := left_sym.struct_info()
ptr_typ := g.typ(left).trim('*') ptr_typ := g.typ(left).trim('*')
if ptr_typ in g.struct_fn_definitions { if ptr_typ in g.struct_fn_definitions {
return ptr_typ return ptr_typ
} }
g.struct_fn_definitions << ptr_typ g.struct_fn_definitions << ptr_typ
left_sym := g.table.get_type_symbol(left)
info := left_sym.struct_info()
g.type_definitions.writeln('static bool ${ptr_typ}_struct_eq($ptr_typ a, $ptr_typ b); // auto') g.type_definitions.writeln('static bool ${ptr_typ}_struct_eq($ptr_typ a, $ptr_typ b); // auto')
mut fn_builder := strings.new_builder(512) mut fn_builder := strings.new_builder(512)
fn_builder.writeln('static bool ${ptr_typ}_struct_eq($ptr_typ a, $ptr_typ b) {') fn_builder.writeln('static bool ${ptr_typ}_struct_eq($ptr_typ a, $ptr_typ b) {')
@ -44,15 +44,15 @@ fn (mut g Gen) gen_struct_equality_fn(left table.Type) string {
} }
fn (mut g Gen) gen_array_equality_fn(left table.Type) string { fn (mut g Gen) gen_array_equality_fn(left table.Type) string {
left_sym := g.table.get_type_symbol(left)
ptr_typ := g.typ(left).trim('*') ptr_typ := g.typ(left).trim('*')
elem_typ := left_sym.array_info().elem_type
ptr_elem_typ := g.typ(elem_typ)
elem_sym := g.table.get_type_symbol(elem_typ)
if ptr_typ in g.array_fn_definitions { if ptr_typ in g.array_fn_definitions {
return ptr_typ return ptr_typ
} }
g.array_fn_definitions << ptr_typ g.array_fn_definitions << ptr_typ
left_sym := g.table.get_type_symbol(left)
elem_typ := left_sym.array_info().elem_type
ptr_elem_typ := g.typ(elem_typ)
elem_sym := g.table.get_type_symbol(elem_typ)
g.type_definitions.writeln('static bool ${ptr_typ}_arr_eq($ptr_typ a, $ptr_typ b); // auto') g.type_definitions.writeln('static bool ${ptr_typ}_arr_eq($ptr_typ a, $ptr_typ b); // auto')
mut fn_builder := strings.new_builder(512) mut fn_builder := strings.new_builder(512)
fn_builder.writeln('static bool ${ptr_typ}_arr_eq($ptr_typ a, $ptr_typ b) {') fn_builder.writeln('static bool ${ptr_typ}_arr_eq($ptr_typ a, $ptr_typ b) {')
@ -87,15 +87,15 @@ fn (mut g Gen) gen_array_equality_fn(left table.Type) string {
} }
fn (mut g Gen) gen_map_equality_fn(left table.Type) string { fn (mut g Gen) gen_map_equality_fn(left table.Type) string {
left_sym := g.table.get_type_symbol(left)
ptr_typ := g.typ(left).trim('*') ptr_typ := g.typ(left).trim('*')
if ptr_typ in g.map_fn_definitions { if ptr_typ in g.map_fn_definitions {
return ptr_typ return ptr_typ
} }
g.map_fn_definitions << ptr_typ
left_sym := g.table.get_type_symbol(left)
value_typ := left_sym.map_info().value_type value_typ := left_sym.map_info().value_type
value_sym := g.table.get_type_symbol(value_typ) value_sym := g.table.get_type_symbol(value_typ)
ptr_value_typ := g.typ(value_typ) ptr_value_typ := g.typ(value_typ)
g.map_fn_definitions << ptr_typ
g.type_definitions.writeln('static bool ${ptr_typ}_map_eq($ptr_typ a, $ptr_typ b); // auto') g.type_definitions.writeln('static bool ${ptr_typ}_map_eq($ptr_typ a, $ptr_typ b); // auto')
mut fn_builder := strings.new_builder(512) mut fn_builder := strings.new_builder(512)
fn_builder.writeln('static bool ${ptr_typ}_map_eq($ptr_typ a, $ptr_typ b) {') fn_builder.writeln('static bool ${ptr_typ}_map_eq($ptr_typ a, $ptr_typ b) {')