mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
v: do a minor optimizations on cmd/v
(#22880)
This commit is contained in:
parent
d2cb41c887
commit
af875ede92
@ -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 {
|
||||
|
@ -9,24 +9,28 @@ 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
|
||||
@ -34,21 +38,25 @@ pub fn sub_i64(ptr &i64, delta int) i64 {
|
||||
|
||||
// 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)))
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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-- {
|
||||
|
Loading…
x
Reference in New Issue
Block a user