mirror of
https://github.com/vlang/v.git
synced 2025-09-16 02:49:31 -04:00
ast: cache ident lookups for consts in ast Expr str (#22101)
This commit is contained in:
parent
c788c08d36
commit
2bf59b14d1
@ -1025,6 +1025,7 @@ pub mut:
|
||||
mod string
|
||||
name string
|
||||
full_name string
|
||||
cached_name string
|
||||
kind IdentKind
|
||||
info IdentInfo
|
||||
is_mut bool // if mut *token* is before name. Use `is_mut()` to lookup mut variable
|
||||
|
@ -395,7 +395,7 @@ __global nested_expr_str_calls = i64(0)
|
||||
const max_nested_expr_str_calls = 300
|
||||
|
||||
// string representation of expr
|
||||
pub fn (x Expr) str() string {
|
||||
pub fn (x &Expr) str() string {
|
||||
str_calls := stdatomic.add_i64(&nested_expr_str_calls, 1)
|
||||
if str_calls > ast.max_nested_expr_str_calls {
|
||||
$if panic_on_deeply_nested_expr_str_calls ? {
|
||||
@ -515,13 +515,22 @@ pub fn (x Expr) str() string {
|
||||
return 'spawn ${x.call_expr}'
|
||||
}
|
||||
Ident {
|
||||
if x.cached_name != '' {
|
||||
return x.cached_name
|
||||
}
|
||||
if obj := x.scope.find('${x.mod}.${x.name}') {
|
||||
if obj is ConstField && x.mod != 'main' {
|
||||
last_mod := x.mod.all_after_last('.')
|
||||
return '${last_mod}.${x.name}'
|
||||
unsafe {
|
||||
x.cached_name = '${last_mod}.${x.name}'
|
||||
}
|
||||
return x.cached_name
|
||||
}
|
||||
}
|
||||
return x.name.clone()
|
||||
unsafe {
|
||||
x.cached_name = x.name.clone()
|
||||
}
|
||||
return x.cached_name
|
||||
}
|
||||
IfExpr {
|
||||
mut parts := []string{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user