mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
checker: optimise out needless string interpolations from the most common case in Checker.expr_or_block_err
This commit is contained in:
parent
803001edaa
commit
55575fd7bd
1 changed files with 12 additions and 3 deletions
|
@ -1064,23 +1064,32 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut c Checker) expr_or_block_err(kind ast.OrKind, expr_name string, pos token.Pos, is_field bool) {
|
// helper for expr_or_block_err
|
||||||
obj_does_not_return_or_is_not := if is_field {
|
fn is_field_to_description(expr_name string, is_field bool) string {
|
||||||
|
return if is_field {
|
||||||
'field `${expr_name}` is not'
|
'field `${expr_name}` is not'
|
||||||
} else {
|
} else {
|
||||||
'function `${expr_name}` does not return'
|
'function `${expr_name}` does not return'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut c Checker) expr_or_block_err(kind ast.OrKind, expr_name string, pos token.Pos, is_field bool) {
|
||||||
match kind {
|
match kind {
|
||||||
.absent {}
|
.absent {
|
||||||
|
// do nothing, most common case; do not be tempted to move the call to is_field_to_description above it, since that will slow it down
|
||||||
|
}
|
||||||
.block {
|
.block {
|
||||||
|
obj_does_not_return_or_is_not := is_field_to_description(expr_name, is_field)
|
||||||
c.error('unexpected `or` block, the ${obj_does_not_return_or_is_not} an Option or a Result',
|
c.error('unexpected `or` block, the ${obj_does_not_return_or_is_not} an Option or a Result',
|
||||||
pos)
|
pos)
|
||||||
}
|
}
|
||||||
.propagate_option {
|
.propagate_option {
|
||||||
|
obj_does_not_return_or_is_not := is_field_to_description(expr_name, is_field)
|
||||||
c.error('unexpected `?`, the ${obj_does_not_return_or_is_not} an Option',
|
c.error('unexpected `?`, the ${obj_does_not_return_or_is_not} an Option',
|
||||||
pos)
|
pos)
|
||||||
}
|
}
|
||||||
.propagate_result {
|
.propagate_result {
|
||||||
|
obj_does_not_return_or_is_not := is_field_to_description(expr_name, is_field)
|
||||||
c.error('unexpected `!`, the ${obj_does_not_return_or_is_not} a Result', pos)
|
c.error('unexpected `!`, the ${obj_does_not_return_or_is_not} a Result', pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue