cgen: fix check for array equality

pull/4350/head
Alexey 2020-04-11 18:25:25 +03:00 committed by GitHub
parent e8afd7a1b7
commit df825506fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -2084,11 +2084,11 @@ fn (g mut Gen) generate_array_equality_fn(ptr_typ string, styp table.Type, sym &
g.definitions.writeln('\t}')
g.definitions.writeln('\tfor (int i = 0; i < a.len; i++) {')
if styp == table.string_type_idx {
g.definitions.writeln('\t\tif (string_ne(*((${ptr_typ}*)(a.data+(i*a.element_size))), *((${ptr_typ}*)(b.data+(i*b.element_size))))) {')
g.definitions.writeln('\t\tif (string_ne(*((${ptr_typ}*)((byte*)a.data+(i*a.element_size))), *((${ptr_typ}*)((byte*)b.data+(i*b.element_size))))) {')
} else if sym.kind == .struct_ {
g.definitions.writeln('\t\tif (memcmp((void*)(a.data+(i*a.element_size)), (void*)(b.data+(i*b.element_size)), a.element_size)) {')
g.definitions.writeln('\t\tif (memcmp((byte*)a.data+(i*a.element_size), (byte*)b.data+(i*b.element_size), a.element_size)) {')
} else {
g.definitions.writeln('\t\tif (*((${ptr_typ}*)(a.data+(i*a.element_size))) != *((${ptr_typ}*)(b.data+(i*b.element_size)))) {')
g.definitions.writeln('\t\tif (*((${ptr_typ}*)((byte*)a.data+(i*a.element_size))) != *((${ptr_typ}*)((byte*)b.data+(i*b.element_size)))) {')
}
g.definitions.writeln('\t\t\treturn false;')
g.definitions.writeln('\t\t}')