mirror of
https://github.com/vlang/v.git
synced 2025-09-13 09:25:45 -04:00
cgen: add caching to contains_ptr return (#22605)
This commit is contained in:
parent
6a8ab333d8
commit
cb4ddb10d9
@ -121,6 +121,7 @@ mut:
|
||||
chan_push_options map[string]string // types for `ch <- x or {...}`
|
||||
mtxs string // array of mutexes if the `lock` has multiple variables
|
||||
labeled_loops map[string]&ast.Stmt
|
||||
contains_ptr_cache map[ast.Type]bool
|
||||
inner_loop &ast.Stmt = unsafe { nil }
|
||||
cur_indexexpr []int // list of nested indexexpr which generates array_set/map_set
|
||||
shareds map[int]string // types with hidden mutex for which decl has been emitted
|
||||
@ -8173,8 +8174,13 @@ pub fn (mut g Gen) get_array_depth(el_typ ast.Type) int {
|
||||
|
||||
// returns true if `t` includes any pointer(s) - during garbage collection heap regions
|
||||
// that contain no pointers do not have to be scanned
|
||||
@[direct_array_access]
|
||||
pub fn (mut g Gen) contains_ptr(el_typ ast.Type) bool {
|
||||
if t_typ := g.contains_ptr_cache[el_typ] {
|
||||
return t_typ
|
||||
}
|
||||
if el_typ.is_any_kind_of_pointer() {
|
||||
g.contains_ptr_cache[el_typ] = true
|
||||
return true
|
||||
}
|
||||
typ := g.unwrap_generic(el_typ)
|
||||
@ -8183,10 +8189,12 @@ pub fn (mut g Gen) contains_ptr(el_typ ast.Type) bool {
|
||||
}
|
||||
sym := g.table.final_sym(typ)
|
||||
if sym.language != .v {
|
||||
g.contains_ptr_cache[typ] = true
|
||||
return true
|
||||
}
|
||||
match sym.kind {
|
||||
.i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .char, .rune, .bool, .enum {
|
||||
g.contains_ptr_cache[typ] = false
|
||||
return false
|
||||
}
|
||||
.array_fixed {
|
||||
@ -8226,6 +8234,7 @@ pub fn (mut g Gen) contains_ptr(el_typ ast.Type) bool {
|
||||
return false
|
||||
}
|
||||
else {
|
||||
g.contains_ptr_cache[typ] = true
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user