]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgo/runtime/go-type-interface.c
1 /* go-type-interface.c -- hash and equality interface functions.
3 Copyright 2009 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 interface. */
13 __go_type_hash_interface (const void *vval
,
14 size_t key_size
__attribute__ ((unused
)))
16 const struct __go_interface
*val
;
17 const struct __go_type_descriptor
*descriptor
;
20 val
= (const struct __go_interface
*) vval
;
21 if (val
->__methods
== NULL
)
23 descriptor
= (const struct __go_type_descriptor
*) val
->__methods
[0];
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 interface. */
34 __go_type_equal_interface (const void *vv1
, const void *vv2
,
35 size_t key_size
__attribute__ ((unused
)))
37 const struct __go_interface
*v1
;
38 const struct __go_interface
*v2
;
39 const struct __go_type_descriptor
* v1_descriptor
;
40 const struct __go_type_descriptor
* v2_descriptor
;
42 v1
= (const struct __go_interface
*) vv1
;
43 v2
= (const struct __go_interface
*) vv2
;
44 if (v1
->__methods
== NULL
|| v2
->__methods
== NULL
)
45 return v1
->__methods
== v2
->__methods
;
46 v1_descriptor
= (const struct __go_type_descriptor
*) v1
->__methods
[0];
47 v2_descriptor
= (const struct __go_type_descriptor
*) v2
->__methods
[0];
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
);