table: optimize generated code for an empty interface (#10624)

pull/10636/head
yuyi 2021-07-01 17:25:40 +08:00 committed by GitHub
parent 41e88423aa
commit 8b901df366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -1037,24 +1037,29 @@ pub fn (t &Table) has_deep_child_no_ref(ts &TypeSymbol, name string) bool {
// complete_interface_check does a MxN check for all M interfaces vs all N types, to determine what types implement what interfaces. // complete_interface_check does a MxN check for all M interfaces vs all N types, to determine what types implement what interfaces.
// It short circuits most checks when an interface can not possibly be implemented by a type. // It short circuits most checks when an interface can not possibly be implemented by a type.
pub fn (mut table Table) complete_interface_check() { pub fn (mut t Table) complete_interface_check() {
util.timing_start(@METHOD) util.timing_start(@METHOD)
defer { defer {
util.timing_measure(@METHOD) util.timing_measure(@METHOD)
} }
for tk, mut tsym in table.type_symbols { for tk, mut tsym in t.type_symbols {
if tsym.kind != .struct_ { if tsym.kind != .struct_ {
continue continue
} }
info := tsym.info as Struct info := tsym.info as Struct
for _, mut idecl in table.interfaces { for _, mut idecl in t.interfaces {
if idecl.methods.len > tsym.methods.len { if idecl.methods.len > tsym.methods.len {
continue continue
} }
if idecl.fields.len > info.fields.len { if idecl.fields.len > info.fields.len {
continue continue
} }
table.does_type_implement_interface(tk, idecl.typ) // empty interface only generate type cast functions of the current module
if idecl.methods.len == 0 && idecl.fields.len == 0
&& tsym.mod != t.get_type_symbol(idecl.typ).mod {
continue
}
t.does_type_implement_interface(tk, idecl.typ)
} }
} }
} }