ast.table: optimize get_final_type_symbol() (#10646)

pull/10647/head
yuyi 2021-07-02 21:59:41 +08:00 committed by GitHub
parent 1486258591
commit 8628b19a3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 4 deletions

View File

@ -496,7 +496,6 @@ pub const invalid_type_symbol = &TypeSymbol{
[inline] [inline]
pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol { pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol {
// println('get_type_symbol $typ')
idx := typ.idx() idx := typ.idx()
if idx > 0 { if idx > 0 {
return unsafe { &t.type_symbols[idx] } return unsafe { &t.type_symbols[idx] }
@ -510,12 +509,11 @@ pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol {
// get_final_type_symbol follows aliases until it gets to a "real" Type // get_final_type_symbol follows aliases until it gets to a "real" Type
[inline] [inline]
pub fn (t &Table) get_final_type_symbol(typ Type) &TypeSymbol { pub fn (t &Table) get_final_type_symbol(typ Type) &TypeSymbol {
idx := typ.idx() mut idx := typ.idx()
if idx > 0 { if idx > 0 {
current_type := t.type_symbols[idx] current_type := t.type_symbols[idx]
if current_type.kind == .alias { if current_type.kind == .alias {
alias_info := current_type.info as Alias idx = (current_type.info as Alias).parent_type.idx()
return t.get_final_type_symbol(alias_info.parent_type)
} }
return unsafe { &t.type_symbols[idx] } return unsafe { &t.type_symbols[idx] }
} }