go-construct-map.c 1.1 KB
Newer Older
1 2 3 4 5 6 7
/* go-construct-map.c -- construct a map from an initializer.

   Copyright 2009 The Go Authors. All rights reserved.
   Use of this source code is governed by a BSD-style
   license that can be found in the LICENSE file.  */

#include <stddef.h>
8
#include <stdint.h>
9 10
#include <stdlib.h>

11
#include "runtime.h"
12
#include "go-type.h"
13

14 15 16 17
extern void *makemap (const struct __go_map_type *, int64_t hint,
		      void *, void *)
  __asm__ (GOSYM_PREFIX "runtime.makemap");

18 19 20
extern void *mapassign (const struct __go_map_type *, void *hmap,
			const void *key)
  __asm__ (GOSYM_PREFIX "runtime.mapassign");
21 22 23

void *
__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

32
  ret = makemap(type, (int64_t) count, NULL, NULL);
33 34 35 36

  entries = (const unsigned char *) ventries;
  for (i = 0; i < count; ++i)
    {
37 38
      p = mapassign (type, ret, entries);
      typedmemmove (type->__val_type, p, entries + val_offset);
39 40 41 42 43
      entries += entry_size;
    }

  return ret;
}