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. */
10 /* A hash function for an empty interface. */
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
;
20 val
= (const struct __go_empty_interface
*) vval
;
21 descriptor
= val
->__type_descriptor
;
22 if (descriptor
== NULL
)
24 size
= descriptor
->__size
;
25 if (__go_is_pointer_type (descriptor
))
26 return descriptor
->__hashfn (&val
->__object
, size
);
28 return descriptor
->__hashfn (val
->__object
, size
);
31 /* An equality function for an empty interface. */
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
))
50 if (__go_is_pointer_type (v1_descriptor
))
51 return v1
->__object
== v2
->__object
;
53 return v1_descriptor
->__equalfn (v1
->__object
, v2
->__object
,
54 v1_descriptor
->__size
);