re PR lto/48086 (bootstrap-lto creates c-common.s with too many sections on x86_64...
[official-gcc.git] / libgo / runtime / go-type-eface.c
blob84ca05ee1dcfbb861059abccb1049adc0e30e91d
1 /* go-type-eface.c -- hash and equality empty interface functions.
3 Copyright 2010 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include "interface.h"
8 #include "go-type.h"
10 /* A hash function for an empty interface. */
12 size_t
13 __go_type_hash_empty_interface (const void *vval,
14 size_t key_size __attribute__ ((unused)))
16 const struct __go_empty_interface *val;
17 const struct __go_type_descriptor *descriptor;
18 size_t size;
20 val = (const struct __go_empty_interface *) vval;
21 descriptor = val->__type_descriptor;
22 if (descriptor == NULL)
23 return 0;
24 size = descriptor->__size;
25 if (__go_is_pointer_type (descriptor))
26 return descriptor->__hashfn (&val->__object, size);
27 else
28 return descriptor->__hashfn (val->__object, size);
31 /* An equality function for an empty interface. */
33 _Bool
34 __go_type_equal_empty_interface (const void *vv1, const void *vv2,
35 size_t key_size __attribute__ ((unused)))
37 const struct __go_empty_interface *v1;
38 const struct __go_empty_interface *v2;
39 const struct __go_type_descriptor* v1_descriptor;
40 const struct __go_type_descriptor* v2_descriptor;
42 v1 = (const struct __go_empty_interface *) vv1;
43 v2 = (const struct __go_empty_interface *) vv2;
44 v1_descriptor = v1->__type_descriptor;
45 v2_descriptor = v2->__type_descriptor;
46 if (v1_descriptor == NULL || v2_descriptor == NULL)
47 return v1_descriptor == v2_descriptor;
48 if (!__go_type_descriptors_equal (v1_descriptor, v2_descriptor))
49 return 0;
50 if (__go_is_pointer_type (v1_descriptor))
51 return v1->__object == v2->__object;
52 else
53 return v1_descriptor->__equalfn (v1->__object, v2->__object,
54 v1_descriptor->__size);