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
|
145
|
13 extern void *makemap (const struct maptype *, intgo hint, void *)
|
111
|
14 __asm__ (GOSYM_PREFIX "runtime.makemap");
|
|
15
|
145
|
16 extern void *mapassign (const struct maptype *, void *hmap, const void *key)
|
111
|
17 __asm__ (GOSYM_PREFIX "runtime.mapassign");
|
|
18
|
|
19 void *
|
145
|
20 __go_construct_map (const struct maptype *type, uintptr_t count,
|
|
21 uintptr_t entry_size, uintptr_t val_offset,
|
|
22 const void *ventries)
|
111
|
23 {
|
|
24 void *ret;
|
|
25 const unsigned char *entries;
|
|
26 uintptr_t i;
|
|
27 void *p;
|
|
28
|
131
|
29 ret = makemap(type, (intgo) count, NULL);
|
111
|
30
|
|
31 entries = (const unsigned char *) ventries;
|
|
32 for (i = 0; i < count; ++i)
|
|
33 {
|
|
34 p = mapassign (type, ret, entries);
|
145
|
35 typedmemmove (type->elem, p, entries + val_offset);
|
111
|
36 entries += entry_size;
|
|
37 }
|
|
38
|
|
39 return ret;
|
|
40 }
|