* gcc.dg/stack-usage-1.c: Remove dg-options line for sh targets
[official-gcc.git] / libgo / runtime / go-map-range.c
blob54444bc21048dfdb50c75de9e65a5a6a134815c5
1 /* go-map-range.c -- implement a range clause over a map.
3 Copyright 2009, 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 "go-assert.h"
8 #include "map.h"
10 /* Initialize a range over a map. */
12 void
13 __go_mapiterinit (const struct __go_map *h, struct __go_hash_iter *it)
15 it->entry = NULL;
16 if (h != NULL)
18 it->map = h;
19 it->next_entry = NULL;
20 it->bucket = 0;
21 --it->bucket;
22 __go_mapiternext(it);
26 /* Move to the next iteration, updating *HITER. */
28 void
29 __go_mapiternext (struct __go_hash_iter *it)
31 const void *entry;
33 entry = it->next_entry;
34 if (entry == NULL)
36 const struct __go_map *map;
37 uintptr_t bucket;
39 map = it->map;
40 bucket = it->bucket;
41 while (1)
43 ++bucket;
44 if (bucket >= map->__bucket_count)
46 /* Map iteration is complete. */
47 it->entry = NULL;
48 return;
50 entry = map->__buckets[bucket];
51 if (entry != NULL)
52 break;
54 it->bucket = bucket;
56 it->entry = entry;
57 it->next_entry = *(const void * const *) entry;
60 /* Get the key of the current iteration. */
62 void
63 __go_mapiter1 (struct __go_hash_iter *it, unsigned char *key)
65 const struct __go_map *map;
66 const struct __go_map_descriptor *descriptor;
67 const struct __go_type_descriptor *key_descriptor;
68 const char *p;
70 map = it->map;
71 descriptor = map->__descriptor;
72 key_descriptor = descriptor->__map_descriptor->__key_type;
73 p = it->entry;
74 __go_assert (p != NULL);
75 __builtin_memcpy (key, p + descriptor->__key_offset, key_descriptor->__size);
78 /* Get the key and value of the current iteration. */
80 void
81 __go_mapiter2 (struct __go_hash_iter *it, unsigned char *key,
82 unsigned char *val)
84 const struct __go_map *map;
85 const struct __go_map_descriptor *descriptor;
86 const struct __go_map_type *map_descriptor;
87 const struct __go_type_descriptor *key_descriptor;
88 const struct __go_type_descriptor *val_descriptor;
89 const char *p;
91 map = it->map;
92 descriptor = map->__descriptor;
93 map_descriptor = descriptor->__map_descriptor;
94 key_descriptor = map_descriptor->__key_type;
95 val_descriptor = map_descriptor->__val_type;
96 p = it->entry;
97 __go_assert (p != NULL);
98 __builtin_memcpy (key, p + descriptor->__key_offset,
99 key_descriptor->__size);
100 __builtin_memcpy (val, p + descriptor->__val_offset,
101 val_descriptor->__size);