Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v: minor optimizations on cmd/v #22878

Merged
merged 6 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vlib/builtin/builtin.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct VCastTypeIndexName {
// will be filled in cgen
__global as_cast_type_indexes []VCastTypeIndexName

@[direct_array_access]
felipensp marked this conversation as resolved.
Show resolved Hide resolved
fn __as_cast(obj voidptr, obj_type int, expected_type int) voidptr {
if obj_type != expected_type {
mut obj_name := as_cast_type_indexes[0].tname.clone()
Expand Down
16 changes: 13 additions & 3 deletions vlib/v/ast/ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -2245,9 +2245,19 @@ pub fn (expr Expr) is_pure_literal() bool {

pub fn (expr Expr) is_auto_deref_var() bool {
return match expr {
Ident { expr.obj is Var && expr.obj.is_auto_deref }
PrefixExpr { expr.op == .amp && expr.right.is_auto_deref_var() }
else { false }
Ident {
if expr.obj is Var {
expr.obj.is_auto_deref
} else {
false
}
}
PrefixExpr {
expr.op == .amp && expr.right.is_auto_deref_var()
}
else {
false
}
felipensp marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
1 change: 1 addition & 0 deletions vlib/v/ast/scope.v
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pub fn (mut s Scope) register(obj ScopeObject) {

// returns the innermost scope containing pos
// pub fn (s &Scope) innermost(pos int) ?&Scope {
@[direct_array_access]
pub fn (s &Scope) innermost(pos int) &Scope {
if s.contains(pos) {
// binary search
Expand Down
6 changes: 2 additions & 4 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -1512,10 +1512,8 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {

using_new_err_struct_save := c.using_new_err_struct
// TODO: remove; this avoids a breaking change in syntax
if node.expr is ast.Ident {
if node.expr.str() == 'err' {
c.using_new_err_struct = true
}
if node.expr is ast.Ident && node.expr.name == 'err' {
c.using_new_err_struct = true
}

// T.name, typeof(expr).name
Expand Down
1 change: 1 addition & 0 deletions vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,7 @@ fn (mut c Checker) go_expr(mut node ast.GoExpr) ast.Type {
}
}

@[direct_array_access]
fn (mut c Checker) set_node_expected_arg_types(mut node ast.CallExpr, func &ast.Fn) {
if node.expected_arg_types.len == 0 {
start_idx := if func.is_method { 1 } else { 0 }
Expand Down
3 changes: 2 additions & 1 deletion vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
c.check_valid_snake_case(field.name, 'field name', field.pos)
}
sym := c.table.sym(field.typ)
field_name, field_name_len := field.name, field.name.len
for j in 0 .. i {
if field.name == node.fields[j].name {
if field_name_len == node.fields[j].name.len && field_name == node.fields[j].name {
felipensp marked this conversation as resolved.
Show resolved Hide resolved
c.error('field name `${field.name}` duplicate', field.pos)
}
}
Expand Down
9 changes: 5 additions & 4 deletions vlib/v/comptime/comptimeinfo.v
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ pub fn (mut ct ComptimeInfo) is_comptime_variant_var(node ast.Ident) bool {
// get_ct_type_var gets the comptime type of the variable (.generic_param, .key_var, etc)
@[inline]
pub fn (mut ct ComptimeInfo) get_ct_type_var(node ast.Expr) ast.ComptimeVarKind {
return if node is ast.Ident && node.obj is ast.Var {
(node.obj as ast.Var).ct_type_var
if node is ast.Ident {
if node.obj is ast.Var {
return node.obj.ct_type_var
}
} else if node is ast.IndexExpr {
return ct.get_ct_type_var(node.left)
} else {
.no_comptime
}
return .no_comptime
}

@[inline]
Expand Down
3 changes: 2 additions & 1 deletion vlib/v/gen/c/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
g.is_shared = field.typ.has_flag(.shared_f)
if mut sym.info is ast.Struct {
mut found_equal_fields := 0
field_name, field_name_len := field.name, field.name.len
for mut sifield in sym.info.fields {
if sifield.name == field.name {
if sifield.name.len == field_name_len && sifield.name == field_name {
felipensp marked this conversation as resolved.
Show resolved Hide resolved
found_equal_fields++
break
}
Expand Down
Loading