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. */
11 /* A hash function for an empty interface. */
14 __go_type_hash_empty_interface (const void *vval
,
15 uintptr_t key_size
__attribute__ ((unused
)))
17 const struct __go_empty_interface
*val
;
18 const struct __go_type_descriptor
*descriptor
;
21 val
= (const struct __go_empty_interface
*) vval
;
22 descriptor
= val
->__type_descriptor
;
23 if (descriptor
== NULL
)
25 size
= descriptor
->__size
;
26 if (__go_is_pointer_type (descriptor
))
27 return descriptor
->__hashfn (&val
->__object
, size
);
29 return descriptor
->__hashfn (val
->__object
, size
);
32 /* An equality function for an empty interface. */
35 __go_type_equal_empty_interface (const void *vv1
, const void *vv2
,
36 uintptr_t key_size
__attribute__ ((unused
)))
38 const struct __go_empty_interface
*v1
;
39 const struct __go_empty_interface
*v2
;
40 const struct __go_type_descriptor
* v1_descriptor
;
41 const struct __go_type_descriptor
* v2_descriptor
;
43 v1
= (const struct __go_empty_interface
*) vv1
;
44 v2
= (const struct __go_empty_interface
*) vv2
;
45 v1_descriptor
= v1
->__type_descriptor
;
46 v2_descriptor
= v2
->__type_descriptor
;
47 if (v1_descriptor
== NULL
|| v2_descriptor
== NULL
)
48 return v1_descriptor
== v2_descriptor
;
49 if (!__go_type_descriptors_equal (v1_descriptor
, v2_descriptor
))
51 if (__go_is_pointer_type (v1_descriptor
))
52 return v1
->__object
== v2
->__object
;
54 return v1_descriptor
->__equalfn (v1
->__object
, v2
->__object
,
55 v1_descriptor
->__size
);