111
|
1 /* go-construct-map.c -- construct a map from an initializer.
|
|
2
|
|
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. */
|
|
6
|
|
7 #include <stddef.h>
|
|
8 #include <stdint.h>
|
|
9 #include <stdlib.h>
|
|
10
|
|
11 #include "runtime.h"
|
|
12 #include "go-type.h"
|
|
13
|
131
|
14 extern void *makemap (const struct __go_map_type *, intgo hint,
|
|
15 void *)
|
111
|
16 __asm__ (GOSYM_PREFIX "runtime.makemap");
|
|
17
|
|
18 extern void *mapassign (const struct __go_map_type *, void *hmap,
|
|
19 const void *key)
|
|
20 __asm__ (GOSYM_PREFIX "runtime.mapassign");
|
|
21
|
|
22 void *
|
|
23 __go_construct_map (const struct __go_map_type *type,
|
|
24 uintptr_t count, uintptr_t entry_size,
|
|
25 uintptr_t val_offset, const void *ventries)
|
|
26 {
|
|
27 void *ret;
|
|
28 const unsigned char *entries;
|
|
29 uintptr_t i;
|
|
30 void *p;
|
|
31
|
131
|
32 ret = makemap(type, (intgo) count, NULL);
|
111
|
33
|
|
34 entries = (const unsigned char *) ventries;
|
|
35 for (i = 0; i < count; ++i)
|
|
36 {
|
|
37 p = mapassign (type, ret, entries);
|
|
38 typedmemmove (type->__val_type, p, entries + val_offset);
|
|
39 entries += entry_size;
|
|
40 }
|
|
41
|
|
42 return ret;
|
|
43 }
|