mirror of
https://github.com/vlang/v.git
synced 2025-09-08 23:07:19 -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.
|
// 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 {
|
pub fn (s string) last_index_u8(c u8) int {
|
||||||
for i := s.len - 1; i >= 0; i-- {
|
for i := s.len - 1; i >= 0; i-- {
|
||||||
if s[i] == c {
|
if s[i] == c {
|
||||||
|
@ -9,24 +9,28 @@ module stdatomic
|
|||||||
// much more.
|
// much more.
|
||||||
|
|
||||||
// add_u64 adds provided delta as an atomic operation
|
// add_u64 adds provided delta as an atomic operation
|
||||||
|
@[inline]
|
||||||
pub fn add_u64(ptr &u64, delta int) u64 {
|
pub fn add_u64(ptr &u64, delta int) u64 {
|
||||||
C.atomic_fetch_add_u64(voidptr(ptr), delta)
|
C.atomic_fetch_add_u64(voidptr(ptr), delta)
|
||||||
return *ptr
|
return *ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
// sub_u64 subtracts provided delta as an atomic operation
|
// sub_u64 subtracts provided delta as an atomic operation
|
||||||
|
@[inline]
|
||||||
pub fn sub_u64(ptr &u64, delta int) u64 {
|
pub fn sub_u64(ptr &u64, delta int) u64 {
|
||||||
C.atomic_fetch_sub_u64(voidptr(ptr), delta)
|
C.atomic_fetch_sub_u64(voidptr(ptr), delta)
|
||||||
return *ptr
|
return *ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
// add_i64 adds provided delta as an atomic operation
|
// add_i64 adds provided delta as an atomic operation
|
||||||
|
@[inline]
|
||||||
pub fn add_i64(ptr &i64, delta int) i64 {
|
pub fn add_i64(ptr &i64, delta int) i64 {
|
||||||
C.atomic_fetch_add_u64(voidptr(ptr), delta)
|
C.atomic_fetch_add_u64(voidptr(ptr), delta)
|
||||||
return *ptr
|
return *ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
// add_i64 subtracts provided delta as an atomic operation
|
// add_i64 subtracts provided delta as an atomic operation
|
||||||
|
@[inline]
|
||||||
pub fn sub_i64(ptr &i64, delta int) i64 {
|
pub fn sub_i64(ptr &i64, delta int) i64 {
|
||||||
C.atomic_fetch_sub_u64(voidptr(ptr), delta)
|
C.atomic_fetch_sub_u64(voidptr(ptr), delta)
|
||||||
return *ptr
|
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
|
// atomic store/load operations have to be used when there might be another concurrent access
|
||||||
// atomicall set a value
|
// atomicall set a value
|
||||||
|
@[inline]
|
||||||
pub fn store_u64(ptr &u64, val u64) {
|
pub fn store_u64(ptr &u64, val u64) {
|
||||||
C.atomic_store_u64(voidptr(ptr), val)
|
C.atomic_store_u64(voidptr(ptr), val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// atomicall get a value
|
// atomicall get a value
|
||||||
|
@[inline]
|
||||||
pub fn load_u64(ptr &u64) u64 {
|
pub fn load_u64(ptr &u64) u64 {
|
||||||
return C.atomic_load_u64(voidptr(ptr))
|
return C.atomic_load_u64(voidptr(ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
// atomicall set a value
|
// atomicall set a value
|
||||||
|
@[inline]
|
||||||
pub fn store_i64(ptr &i64, val i64) {
|
pub fn store_i64(ptr &i64, val i64) {
|
||||||
C.atomic_store_u64(voidptr(ptr), val)
|
C.atomic_store_u64(voidptr(ptr), val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// atomicall get a value
|
// atomicall get a value
|
||||||
|
@[inline]
|
||||||
pub fn load_i64(ptr &i64) i64 {
|
pub fn load_i64(ptr &i64) i64 {
|
||||||
return i64(C.atomic_load_u64(voidptr(ptr)))
|
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 {
|
pub fn (e Expr) is_nil() bool {
|
||||||
return e is Nil || (e is UnsafeExpr && e.expr is Nil)
|
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 {
|
pub fn type_can_start_with_token(tok &token.Token) bool {
|
||||||
return match tok.kind {
|
return match tok.kind {
|
||||||
.name {
|
.name {
|
||||||
|
@ -491,6 +491,7 @@ fn (mut c Checker) file_has_main_fn(file &ast.File) bool {
|
|||||||
return has_main_fn
|
return has_main_fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@[direct_array_access]
|
||||||
fn (mut c Checker) check_valid_snake_case(name string, identifier string, pos token.Pos) {
|
fn (mut c Checker) check_valid_snake_case(name string, identifier string, pos token.Pos) {
|
||||||
if c.pref.translated || c.file.is_translated {
|
if c.pref.translated || c.file.is_translated {
|
||||||
return
|
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() {
|
fn (mut p Parser) next() {
|
||||||
p.prev_tok = p.tok
|
p.prev_tok = p.tok
|
||||||
p.tok = p.peek_tok
|
p.tok = p.peek_tok
|
||||||
|
@ -1183,10 +1183,12 @@ fn (mut s Scanner) invalid_character() {
|
|||||||
s.error('invalid character `${c}`')
|
s.error('invalid character `${c}`')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@[inline]
|
||||||
fn (s &Scanner) current_column() int {
|
fn (s &Scanner) current_column() int {
|
||||||
return s.pos - s.last_nl_pos
|
return s.pos - s.last_nl_pos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@[direct_array_access]
|
||||||
fn (s &Scanner) count_symbol_before(p int, sym u8) int {
|
fn (s &Scanner) count_symbol_before(p int, sym u8) int {
|
||||||
mut count := 0
|
mut count := 0
|
||||||
for i := p; i >= 0; i-- {
|
for i := p; i >= 0; i-- {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user