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

[if vfmt] function attribute for skipping functions for performance

This commit is contained in:
Alexander Medvednikov 2019-10-27 02:03:06 +03:00
parent ee51313e2c
commit ef022c2326
3 changed files with 12 additions and 2 deletions

View File

@ -113,6 +113,7 @@ pub mut:
// This is on by default, since a vast majority of users do not // This is on by default, since a vast majority of users do not
// work on the builtin module itself. // work on the builtin module itself.
//generating_vh bool //generating_vh bool
comptime_define string // -D vfmt for `if $vfmt {`
} }
// Should be called by main at the end of the compilation process, to cleanup // Should be called by main at the end of the compilation process, to cleanup
@ -765,6 +766,7 @@ pub fn new_v(args[]string) &V {
joined_args := args.join(' ') joined_args := args.join(' ')
target_os := get_arg(joined_args, 'os', '') target_os := get_arg(joined_args, 'os', '')
comptime_define := get_arg(joined_args, 'd', '')
mut out_name := get_arg(joined_args, 'o', 'a.out') mut out_name := get_arg(joined_args, 'o', 'a.out')
mut dir := args.last() mut dir := args.last()
@ -922,6 +924,7 @@ pub fn new_v(args[]string) &V {
cflags: cflags cflags: cflags
ccompiler: find_c_compiler() ccompiler: find_c_compiler()
building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || dir.contains('vlib')) building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || dir.contains('vlib'))
comptime_define: comptime_define
} }
if pref.is_verbose || pref.is_debug { if pref.is_verbose || pref.is_debug {
println('C compiler=$pref.ccompiler') println('C compiler=$pref.ccompiler')

View File

@ -3872,7 +3872,13 @@ fn (p mut Parser) js_decode() string {
fn (p mut Parser) attribute() { fn (p mut Parser) attribute() {
p.check(.lsbr) p.check(.lsbr)
if p.tok == .key_if {
// [if vfmt]
p.next()
p.attr = 'if ' + p.check_name()
} else {
p.attr = p.check_name() p.attr = p.check_name()
}
attr_token_idx := p.cur_tok_index() attr_token_idx := p.cur_tok_index()
if p.tok == .colon { if p.tok == .colon {
p.check(.colon) p.check(.colon)

View File

@ -7,6 +7,7 @@ module compiler
import strings import strings
// fmt helpers // fmt helpers
//[if vfmt]
fn (scanner mut Scanner) fgen(s_ string) { fn (scanner mut Scanner) fgen(s_ string) {
mut s := s_ mut s := s_
if scanner.fmt_line_empty { if scanner.fmt_line_empty {