1.1 --- a/templates/progops.c Fri Dec 02 22:26:53 2016 +0100
1.2 +++ b/templates/progops.c Sat Dec 03 01:23:18 2016 +0100
1.3 @@ -37,32 +37,6 @@
1.4 return data;
1.5 }
1.6
1.7 -__mapping *__new_mapping(unsigned int n)
1.8 -{
1.9 - /* Allocate a number of buckets. */
1.10 -
1.11 - __mapping *data = (__mapping *) __ALLOCATE(1, __MAPPING_SIZE(n));
1.12 - unsigned int i;
1.13 -
1.14 - /* Create arrays for key and value buckets. */
1.15 -
1.16 - data->keys = (__fragment **) __ALLOCATE(n, sizeof(__fragment *));
1.17 - data->values = (__fragment **) __ALLOCATE(n, sizeof(__fragment *));
1.18 -
1.19 - /* Allocate fragments with an initial size of 2, assuming a mostly uniform
1.20 - distribution of values across the buckets will occur. */
1.21 -
1.22 - for (i = 0; i < n; i++)
1.23 - {
1.24 - data->keys[i] = __new_fragment(2);
1.25 - data->values[i] = __new_fragment(2);
1.26 - }
1.27 -
1.28 - data->size = 0;
1.29 - data->capacity = n;
1.30 - return data;
1.31 -}
1.32 -
1.33 void __newdata_sequence(__attr args[], unsigned int number)
1.34 {
1.35 /* Calculate the size of the fragment. */
1.36 @@ -87,32 +61,20 @@
1.37
1.38 void __newdata_mapping(__attr args[], unsigned int number)
1.39 {
1.40 - __mapping *data = __new_mapping(number);
1.41 - __attr attr = {0, .mapvalue=data};
1.42 - __fragment *f;
1.43 - __attr callargs[3];
1.44 - unsigned int i;
1.45 + __attr dict = args[0];
1.46 + __attr callargs[2];
1.47
1.48 - /* Store a reference to the data in the object's __data__ attribute. */
1.49 + /* Create a temporary list using the arguments. */
1.50
1.51 - __store_via_object(args[0].value, __pos___data__, attr);
1.52 -
1.53 - /* Store the given number of values, starting from the second element. */
1.54 + __newliteral___builtins___list_list(args, number);
1.55
1.56 - callargs[0] = args[0];
1.57 -
1.58 - for (i = 1; i <= number; i++)
1.59 - {
1.60 - /* Obtain the tuple elements. */
1.61 + /* Call __init__ with the dict object and list argument. */
1.62
1.63 - f = __load_via_object(args[i].value, __pos___data__).seqvalue;
1.64 - callargs[1] = f->attrs[0];
1.65 - callargs[2] = f->attrs[1];
1.66 + callargs[0] = dict;
1.67 + callargs[1] = args[0];
1.68
1.69 - /* Call __setitem__ with the key and value. */
1.70 -
1.71 - __fn___builtins___dict_dict___setitem__(callargs);
1.72 - }
1.73 + __fn___builtins___dict_dict___init__(callargs);
1.74 + args[0] = dict;
1.75 }
1.76
1.77 #endif /* __HAVE___builtins___dict_dict */