Skip to content

Commit

Permalink
ast: reduce allocations in empty_comptime_const_expr (#23324)
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman authored Dec 31, 2024
1 parent ab707dc commit 4b6b852
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 4 additions & 3 deletions vlib/v/ast/ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pub:
pub const empty_expr = Expr(EmptyExpr(0))
pub const empty_stmt = Stmt(EmptyStmt{})
pub const empty_node = Node(EmptyNode{})
pub const empty_comptime_const_value = ComptTimeConstValue(EmptyExpr(0))

// `{stmts}` or `unsafe {stmts}`
pub struct Block {
Expand Down Expand Up @@ -398,7 +399,7 @@ pub mut:
end_comments []Comment // comments that after const field
// the comptime_expr_value field is filled by the checker, when it has enough
// info to evaluate the constant at compile time
comptime_expr_value ComptTimeConstValue = empty_comptime_const_expr()
comptime_expr_value ComptTimeConstValue = empty_comptime_const_value
}

// const declaration
Expand Down Expand Up @@ -1132,9 +1133,9 @@ pub mut:
or_block OrExpr

ct_left_value_evaled bool
ct_left_value ComptTimeConstValue = empty_comptime_const_expr()
ct_left_value ComptTimeConstValue = empty_comptime_const_value
ct_right_value_evaled bool
ct_right_value ComptTimeConstValue = empty_comptime_const_expr()
ct_right_value ComptTimeConstValue = empty_comptime_const_value

before_op_comments []Comment
after_op_comments []Comment
Expand Down
5 changes: 0 additions & 5 deletions vlib/v/ast/comptime_const_values.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ pub type ComptTimeConstValue = EmptyExpr

//| int

// empty_comptime_const_expr return an EmptyExpr.
pub fn empty_comptime_const_expr() ComptTimeConstValue {
return EmptyExpr(0)
}

// i8 tries to return a `ComptTimeConstValue` as `i8` type.
pub fn (val ComptTimeConstValue) i8() ?i8 {
x := val.i64()?
Expand Down

0 comments on commit 4b6b852

Please sign in to comment.