Skip to content

Commit

Permalink
v: do a minor optimizations on cmd/v (#22880)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Nov 17, 2024
1 parent d2cb41c commit af875ed
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/builtin/string.v
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ pub fn (s string) index_u8_last(c u8) int {
}

// last_index_u8 returns the index of the last occurrence of byte `c` if it was found in the string.
@[inline]
@[direct_array_access; inline]
pub fn (s string) last_index_u8(c u8) int {
for i := s.len - 1; i >= 0; i-- {
if s[i] == c {
Expand Down
8 changes: 8 additions & 0 deletions vlib/sync/stdatomic/atomic.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,54 @@ module stdatomic
// much more.

// add_u64 adds provided delta as an atomic operation
@[inline]
pub fn add_u64(ptr &u64, delta int) u64 {
C.atomic_fetch_add_u64(voidptr(ptr), delta)
return *ptr
}

// sub_u64 subtracts provided delta as an atomic operation
@[inline]
pub fn sub_u64(ptr &u64, delta int) u64 {
C.atomic_fetch_sub_u64(voidptr(ptr), delta)
return *ptr
}

// add_i64 adds provided delta as an atomic operation
@[inline]
pub fn add_i64(ptr &i64, delta int) i64 {
C.atomic_fetch_add_u64(voidptr(ptr), delta)
return *ptr
}

// add_i64 subtracts provided delta as an atomic operation
@[inline]
pub fn sub_i64(ptr &i64, delta int) i64 {
C.atomic_fetch_sub_u64(voidptr(ptr), delta)
return *ptr
}

// atomic store/load operations have to be used when there might be another concurrent access
// atomicall set a value
@[inline]
pub fn store_u64(ptr &u64, val u64) {
C.atomic_store_u64(voidptr(ptr), val)
}

// atomicall get a value
@[inline]
pub fn load_u64(ptr &u64) u64 {
return C.atomic_load_u64(voidptr(ptr))
}

// atomicall set a value
@[inline]
pub fn store_i64(ptr &i64, val i64) {
C.atomic_store_u64(voidptr(ptr), val)
}

// atomicall get a value
@[inline]
pub fn load_i64(ptr &i64) i64 {
return i64(C.atomic_load_u64(voidptr(ptr)))
}
2 changes: 2 additions & 0 deletions vlib/v/ast/ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -2675,10 +2675,12 @@ pub fn (expr Expr) is_literal() bool {
}
}

@[inline]
pub fn (e Expr) is_nil() bool {
return e is Nil || (e is UnsafeExpr && e.expr is Nil)
}

@[direct_array_access]
pub fn type_can_start_with_token(tok &token.Token) bool {
return match tok.kind {
.name {
Expand Down
1 change: 1 addition & 0 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ fn (mut c Checker) file_has_main_fn(file &ast.File) bool {
return has_main_fn
}

@[direct_array_access]
fn (mut c Checker) check_valid_snake_case(name string, identifier string, pos token.Pos) {
if c.pref.translated || c.file.is_translated {
return
Expand Down
1 change: 1 addition & 0 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ fn (mut p Parser) mark_last_call_return_as_used(mut last_stmt ast.Stmt) {
}
}

@[inline]
fn (mut p Parser) next() {
p.prev_tok = p.tok
p.tok = p.peek_tok
Expand Down
2 changes: 2 additions & 0 deletions vlib/v/scanner/scanner.v
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,12 @@ fn (mut s Scanner) invalid_character() {
s.error('invalid character `${c}`')
}

@[inline]
fn (s &Scanner) current_column() int {
return s.pos - s.last_nl_pos
}

@[direct_array_access]
fn (s &Scanner) count_symbol_before(p int, sym u8) int {
mut count := 0
for i := p; i >= 0; i-- {
Expand Down

0 comments on commit af875ed

Please sign in to comment.