diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index 50ae015fe6ce56..382bec968e6027 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -187,26 +187,32 @@ pub mut: len int } +@[inline] fn map_eq_string(a voidptr, b voidptr) bool { return fast_string_eq(*unsafe { &string(a) }, *unsafe { &string(b) }) } +@[inline] fn map_eq_int_1(a voidptr, b voidptr) bool { return unsafe { *&u8(a) == *&u8(b) } } +@[inline] fn map_eq_int_2(a voidptr, b voidptr) bool { return unsafe { *&u16(a) == *&u16(b) } } +@[inline] fn map_eq_int_4(a voidptr, b voidptr) bool { return unsafe { *&u32(a) == *&u32(b) } } +@[inline] fn map_eq_int_8(a voidptr, b voidptr) bool { return unsafe { *&u64(a) == *&u64(b) } } +@[inline] fn map_clone_string(dest voidptr, pkey voidptr) { unsafe { s := *&string(pkey) @@ -214,36 +220,42 @@ fn map_clone_string(dest voidptr, pkey voidptr) { } } +@[inline] fn map_clone_int_1(dest voidptr, pkey voidptr) { unsafe { *&u8(dest) = *&u8(pkey) } } +@[inline] fn map_clone_int_2(dest voidptr, pkey voidptr) { unsafe { *&u16(dest) = *&u16(pkey) } } +@[inline] fn map_clone_int_4(dest voidptr, pkey voidptr) { unsafe { *&u32(dest) = *&u32(pkey) } } +@[inline] fn map_clone_int_8(dest voidptr, pkey voidptr) { unsafe { *&u64(dest) = *&u64(pkey) } } +@[inline] fn map_free_string(pkey voidptr) { unsafe { (*&string(pkey)).free() } } +@[inline] fn map_free_nop(_ voidptr) { } diff --git a/vlib/v/gen/c/auto_eq_methods.v b/vlib/v/gen/c/auto_eq_methods.v index e5cb1edb73a0c5..ef398d66e81340 100644 --- a/vlib/v/gen/c/auto_eq_methods.v +++ b/vlib/v/gen/c/auto_eq_methods.v @@ -66,7 +66,7 @@ fn (mut g Gen) gen_sumtype_equality_fn(left_type ast.Type) string { right_typ := g.read_field(left_type, '_typ', 'b') mut fn_builder := strings.new_builder(512) - fn_builder.writeln('static bool ${ptr_styp}_sumtype_eq(${ptr_styp} a, ${ptr_styp} b) {') + fn_builder.writeln('static inline bool ${ptr_styp}_sumtype_eq(${ptr_styp} a, ${ptr_styp} b) {') fn_builder.writeln('\tif (${left_typ} != ${right_typ}) { return false; }') fn_builder.writeln('\tif (${left_typ} == ${right_typ} && ${right_typ} == 0) { return true; } // uninitialized') for typ in info.variants { @@ -190,7 +190,7 @@ fn (mut g Gen) gen_struct_equality_fn(left_type ast.Type) string { defer { g.auto_fn_definitions << fn_builder.str() } - fn_builder.writeln('static bool ${fn_name}_struct_eq(${ptr_styp} a, ${ptr_styp} b) {') + fn_builder.writeln('static inline bool ${fn_name}_struct_eq(${ptr_styp} a, ${ptr_styp} b) {') // overloaded if left.sym.has_method('==') { @@ -290,7 +290,7 @@ fn (mut g Gen) gen_alias_equality_fn(left_type ast.Type) string { g.definitions.writeln('static bool ${ptr_styp}_alias_eq(${ptr_styp} a, ${ptr_styp} b); // auto') mut fn_builder := strings.new_builder(512) - fn_builder.writeln('static bool ${ptr_styp}_alias_eq(${ptr_styp} a, ${ptr_styp} b) {') + fn_builder.writeln('static inline bool ${ptr_styp}_alias_eq(${ptr_styp} a, ${ptr_styp} b) {') is_option := left.typ.has_flag(.option) @@ -351,7 +351,7 @@ fn (mut g Gen) gen_array_equality_fn(left_type ast.Type) string { g.definitions.writeln('static bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b); // auto') mut fn_builder := strings.new_builder(512) - fn_builder.writeln('static bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b) {') + fn_builder.writeln('static inline bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b) {') left_len := g.read_field(left_type, 'len', 'a') right_len := g.read_field(left_type, 'len', 'b') @@ -432,7 +432,7 @@ fn (mut g Gen) gen_fixed_array_equality_fn(left_type ast.Type) string { right := if left_type.has_flag(.option) { 'b.data' } else { 'b' } mut fn_builder := strings.new_builder(512) - fn_builder.writeln('static bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b) {') + fn_builder.writeln('static inline bool ${ptr_styp}_arr_eq(${ptr_styp} a, ${ptr_styp} b) {') fn_builder.writeln('\tfor (int i = 0; i < ${size}; ++i) {') // compare every pair of elements of the two fixed arrays if elem.sym.kind == .string { @@ -494,7 +494,7 @@ fn (mut g Gen) gen_map_equality_fn(left_type ast.Type) string { b := if left.typ.has_flag(.option) { g.read_map_from_option(left.typ, 'b') } else { '&b' } mut fn_builder := strings.new_builder(512) - fn_builder.writeln('static bool ${ptr_styp}_map_eq(${ptr_styp} a, ${ptr_styp} b) {') + fn_builder.writeln('static inline bool ${ptr_styp}_map_eq(${ptr_styp} a, ${ptr_styp} b) {') fn_builder.writeln('\tif (${left_len} != ${right_len}) {') fn_builder.writeln('\t\treturn false;') fn_builder.writeln('\t}') @@ -587,7 +587,7 @@ fn (mut g Gen) gen_interface_equality_fn(left_type ast.Type) string { right_arg := g.read_field(left_type, '_typ', 'b') fn_builder.writeln('static int v_typeof_interface_idx_${idx_fn}(int sidx); // for auto eq method') - fn_builder.writeln('static bool ${fn_name}_interface_eq(${ptr_styp} a, ${ptr_styp} b) {') + fn_builder.writeln('static inline bool ${fn_name}_interface_eq(${ptr_styp} a, ${ptr_styp} b) {') fn_builder.writeln('\tif (${left_arg} == ${right_arg}) {') fn_builder.writeln('\t\tint idx = v_typeof_interface_idx_${idx_fn}(${left_arg});') if info is ast.Interface {