mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
Revert "ast,cgen: small speedup for the 1m_statements_in_1_fn.v"
This reverts commit 14b5cf433d12c59240e9fab6bd2ec68133f4a7c3.
This commit is contained in:
parent
11bffc957a
commit
8eded2e025
@ -272,12 +272,10 @@ pub fn (t Type) atomic_typename() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
|
||||||
pub fn sharetype_from_flags(is_shared bool, is_atomic bool) ShareType {
|
pub fn sharetype_from_flags(is_shared bool, is_atomic bool) ShareType {
|
||||||
return unsafe { ShareType(int(u32(is_atomic) << 1) | int(is_shared)) }
|
return unsafe { ShareType(int(u32(is_atomic) << 1) | int(is_shared)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
|
||||||
pub fn (t Type) share() ShareType {
|
pub fn (t Type) share() ShareType {
|
||||||
return sharetype_from_flags(t.has_flag(.shared_f), t.has_flag(.atomic_f))
|
return sharetype_from_flags(t.has_flag(.shared_f), t.has_flag(.atomic_f))
|
||||||
}
|
}
|
||||||
@ -285,7 +283,7 @@ pub fn (t Type) share() ShareType {
|
|||||||
// return TypeSymbol idx for `t`
|
// return TypeSymbol idx for `t`
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (t Type) idx() int {
|
pub fn (t Type) idx() int {
|
||||||
return int(t) & 0xffff
|
return u16(t) & 0xffff
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
@ -309,14 +307,13 @@ pub fn (t Type) nr_muls() int {
|
|||||||
pub fn (t Type) is_ptr() bool {
|
pub fn (t Type) is_ptr() bool {
|
||||||
// any normal pointer, i.e. &Type, &&Type etc;
|
// any normal pointer, i.e. &Type, &&Type etc;
|
||||||
// Note: voidptr, charptr and byteptr are NOT included!
|
// Note: voidptr, charptr and byteptr are NOT included!
|
||||||
return (int(t) >> 16) & 0xff != 0
|
return (int(t) >> 16) & 0xff > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_pointer() bool {
|
pub fn (typ Type) is_pointer() bool {
|
||||||
// builtin pointer types (voidptr, byteptr, charptr)
|
// builtin pointer types (voidptr, byteptr, charptr)
|
||||||
return typ.idx() in [ast.voidptr_type_idx, ast.byteptr_type_idx, ast.charptr_type_idx,
|
return typ.idx() in ast.pointer_type_idxs
|
||||||
ast.nil_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
@ -326,8 +323,7 @@ pub fn (typ Type) is_voidptr() bool {
|
|||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (t Type) is_any_kind_of_pointer() bool {
|
pub fn (t Type) is_any_kind_of_pointer() bool {
|
||||||
return (int(t) >> 16) & 0xff != 0
|
return (int(t) >> 16) & 0xff > 0 || (u16(t) & 0xffff) in ast.pointer_type_idxs
|
||||||
|| u16(t) in [ast.voidptr_type_idx, ast.byteptr_type_idx, ast.charptr_type_idx, ast.nil_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set nr_muls on `t` and return it
|
// set nr_muls on `t` and return it
|
||||||
@ -388,7 +384,7 @@ pub fn (t Type) clear_flags(flags ...TypeFlag) Type {
|
|||||||
// return true if `flag` is set on `t`
|
// return true if `flag` is set on `t`
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (t Type) has_flag(flag TypeFlag) bool {
|
pub fn (t Type) has_flag(flag TypeFlag) bool {
|
||||||
return int(t) & (1 << (int(flag) + 24)) != 0
|
return int(t) & (1 << (int(flag) + 24)) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug returns a verbose representation of the information in ts, useful for tracing/debugging
|
// debug returns a verbose representation of the information in ts, useful for tracing/debugging
|
||||||
@ -488,50 +484,42 @@ pub fn new_type_ptr(idx int, nr_muls int) Type {
|
|||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_float() bool {
|
pub fn (typ Type) is_float() bool {
|
||||||
return !typ.is_ptr()
|
return !typ.is_ptr() && typ.idx() in ast.float_type_idxs
|
||||||
&& typ.idx() in [ast.f32_type_idx, ast.f64_type_idx, ast.float_literal_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_int() bool {
|
pub fn (typ Type) is_int() bool {
|
||||||
return !typ.is_ptr()
|
return !typ.is_ptr() && typ.idx() in ast.integer_type_idxs
|
||||||
&& typ.idx() in [ast.i8_type_idx, ast.i16_type_idx, ast.int_type_idx, ast.i64_type_idx, ast.u8_type_idx, ast.u16_type_idx, ast.u32_type_idx, ast.u64_type_idx, ast.isize_type_idx, ast.usize_type_idx, ast.int_literal_type_idx, ast.rune_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_int_valptr() bool {
|
pub fn (typ Type) is_int_valptr() bool {
|
||||||
return typ.is_ptr()
|
return typ.is_ptr() && typ.idx() in ast.integer_type_idxs
|
||||||
&& typ.idx() in [ast.i8_type_idx, ast.i16_type_idx, ast.int_type_idx, ast.i64_type_idx, ast.u8_type_idx, ast.u16_type_idx, ast.u32_type_idx, ast.u64_type_idx, ast.isize_type_idx, ast.usize_type_idx, ast.int_literal_type_idx, ast.rune_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_float_valptr() bool {
|
pub fn (typ Type) is_float_valptr() bool {
|
||||||
return typ.is_ptr()
|
return typ.is_ptr() && typ.idx() in ast.float_type_idxs
|
||||||
&& typ.idx() in [ast.f32_type_idx, ast.f64_type_idx, ast.float_literal_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_pure_int() bool {
|
pub fn (typ Type) is_pure_int() bool {
|
||||||
return int(typ) in [ast.i8_type_idx, ast.i16_type_idx, ast.int_type_idx, ast.i64_type_idx,
|
return int(typ) in ast.integer_type_idxs
|
||||||
ast.u8_type_idx, ast.u16_type_idx, ast.u32_type_idx, ast.u64_type_idx, ast.isize_type_idx,
|
|
||||||
ast.usize_type_idx, ast.int_literal_type_idx, ast.rune_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_pure_float() bool {
|
pub fn (typ Type) is_pure_float() bool {
|
||||||
return int(typ) in [ast.f32_type_idx, ast.f64_type_idx, ast.float_literal_type_idx]
|
return int(typ) in ast.float_type_idxs
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_signed() bool {
|
pub fn (typ Type) is_signed() bool {
|
||||||
return typ.idx() in [ast.char_type_idx, ast.i8_type_idx, ast.i16_type_idx, ast.int_type_idx,
|
return typ.idx() in ast.signed_integer_type_idxs
|
||||||
ast.i64_type_idx, ast.isize_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_unsigned() bool {
|
pub fn (typ Type) is_unsigned() bool {
|
||||||
return typ.idx() in [ast.u8_type_idx, ast.u16_type_idx, ast.u32_type_idx, ast.u64_type_idx,
|
return typ.idx() in ast.unsigned_integer_type_idxs
|
||||||
ast.usize_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (typ Type) flip_signedness() Type {
|
pub fn (typ Type) flip_signedness() Type {
|
||||||
@ -557,10 +545,7 @@ pub fn (typ Type) is_int_literal() bool {
|
|||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_number() bool {
|
pub fn (typ Type) is_number() bool {
|
||||||
return (int(typ) & 0xffffff) in [ast.i8_type_idx, ast.i16_type_idx, ast.int_type_idx,
|
return typ.clear_flags() in ast.number_type_idxs
|
||||||
ast.i64_type_idx, ast.u8_type_idx, ast.char_type_idx, ast.u16_type_idx, ast.u32_type_idx,
|
|
||||||
ast.u64_type_idx, ast.isize_type_idx, ast.usize_type_idx, ast.f32_type_idx, ast.f64_type_idx,
|
|
||||||
ast.int_literal_type_idx, ast.float_literal_type_idx, ast.rune_type_idx]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
@ -225,10 +225,10 @@ fn (mut g Gen) gen_alias_equality_fn(left_type ast.Type) string {
|
|||||||
}
|
}
|
||||||
g.generated_eq_fns << left_type
|
g.generated_eq_fns << left_type
|
||||||
info := left.sym.info as ast.Alias
|
info := left.sym.info as ast.Alias
|
||||||
g.definitions.writeln('static inline bool ${ptr_styp}_alias_eq(${ptr_styp} a, ${ptr_styp} b); // auto')
|
g.definitions.writeln('static bool ${ptr_styp}_alias_eq(${ptr_styp} a, ${ptr_styp} b); // auto')
|
||||||
|
|
||||||
mut fn_builder := strings.new_builder(512)
|
mut fn_builder := strings.new_builder(512)
|
||||||
fn_builder.writeln('static inline bool ${ptr_styp}_alias_eq(${ptr_styp} a, ${ptr_styp} b) {')
|
fn_builder.writeln('static bool ${ptr_styp}_alias_eq(${ptr_styp} a, ${ptr_styp} b) {')
|
||||||
|
|
||||||
is_option := left.typ.has_flag(.option)
|
is_option := left.typ.has_flag(.option)
|
||||||
|
|
||||||
@ -283,10 +283,10 @@ fn (mut g Gen) gen_array_equality_fn(left_type ast.Type) string {
|
|||||||
g.generated_eq_fns << left_type
|
g.generated_eq_fns << left_type
|
||||||
elem := g.unwrap(left.sym.array_info().elem_type)
|
elem := g.unwrap(left.sym.array_info().elem_type)
|
||||||
ptr_elem_styp := g.typ(elem.typ)
|
ptr_elem_styp := g.typ(elem.typ)
|
||||||
g.definitions.writeln('static inline bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b); // auto')
|
g.definitions.writeln('static bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b); // auto')
|
||||||
|
|
||||||
mut fn_builder := strings.new_builder(512)
|
mut fn_builder := strings.new_builder(512)
|
||||||
fn_builder.writeln('static inline bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b) {')
|
fn_builder.writeln('static bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b) {')
|
||||||
|
|
||||||
left_len := g.read_field(left_type, 'len', 'a')
|
left_len := g.read_field(left_type, 'len', 'a')
|
||||||
right_len := g.read_field(left_type, 'len', 'b')
|
right_len := g.read_field(left_type, 'len', 'b')
|
||||||
@ -353,13 +353,13 @@ fn (mut g Gen) gen_fixed_array_equality_fn(left_type ast.Type) string {
|
|||||||
elem_info := left_typ.sym.array_fixed_info()
|
elem_info := left_typ.sym.array_fixed_info()
|
||||||
elem := g.unwrap(elem_info.elem_type)
|
elem := g.unwrap(elem_info.elem_type)
|
||||||
size := elem_info.size
|
size := elem_info.size
|
||||||
g.definitions.writeln('static inline bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b); // auto')
|
g.definitions.writeln('static bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b); // auto')
|
||||||
|
|
||||||
left := if left_type.has_flag(.option) { 'a.data' } else { 'a' }
|
left := if left_type.has_flag(.option) { 'a.data' } else { 'a' }
|
||||||
right := if left_type.has_flag(.option) { 'b.data' } else { 'b' }
|
right := if left_type.has_flag(.option) { 'b.data' } else { 'b' }
|
||||||
|
|
||||||
mut fn_builder := strings.new_builder(512)
|
mut fn_builder := strings.new_builder(512)
|
||||||
fn_builder.writeln('static inline bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b) {')
|
fn_builder.writeln('static bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b) {')
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < ${size}; ++i) {')
|
fn_builder.writeln('\tfor (int i = 0; i < ${size}; ++i) {')
|
||||||
// compare every pair of elements of the two fixed arrays
|
// compare every pair of elements of the two fixed arrays
|
||||||
if elem.sym.kind == .string {
|
if elem.sym.kind == .string {
|
||||||
|
Loading…
Reference in New Issue
Block a user