1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtins: ustring comparisons, concatenation and other functions

This commit is contained in:
Henrixounez
2019-09-20 18:07:38 +02:00
committed by Alexander Medvednikov
parent fd68c44dfa
commit ffcff9ebd4
4 changed files with 178 additions and 9 deletions

View File

@@ -861,12 +861,18 @@ fn (p mut Parser) fn_call_args(f mut Fn) &Fn {
}
}
p.expected_type = arg.typ
typ := p.bool_expression()
mut typ := p.bool_expression()
// Optimize `println`: replace it with `printf` to avoid extra allocations and
// function calls.
// `println(777)` => `printf("%d\n", 777)`
// (If we don't check for void, then V will compile `println(func())`)
if i == 0 && (f.name == 'println' || f.name == 'print') && typ != 'string' && typ != 'void' {
if i == 0 && (f.name == 'println' || f.name == 'print') && typ == 'ustring' {
if typ == 'ustring' {
p.gen('.s')
}
typ = 'string'
}
if i == 0 && (f.name == 'println' || f.name == 'print') && typ != 'string' && typ != 'ustring' && typ != 'void' {
T := p.table.find_type(typ)
$if !windows {
$if !js {