Skip to content

Instantly share code, notes, and snippets.

@mlschroe
Created July 11, 2011 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlschroe/1075727 to your computer and use it in GitHub Desktop.
Save mlschroe/1075727 to your computer and use it in GitHub Desktop.
--- ./nqp/src/6model/reprs/P6opaque.c.orig 2011-07-11 11:05:56.000000000 +0000
+++ ./nqp/src/6model/reprs/P6opaque.c 2011-07-11 11:48:18.000000000 +0000
@@ -185,7 +185,6 @@ static void compute_allocation_strategy(
INTVAL info_alloc = num_attrs == 0 ? 1 : num_attrs;
INTVAL cur_pmc_attr = 0;
INTVAL cur_str_attr = 0;
- INTVAL cur_avc_attr = 0;
INTVAL i;
/* Allocate offset array and GC mark info arrays. */
@@ -250,11 +249,9 @@ static void compute_allocation_strategy(
cur_pmc_attr++;
if (!PMC_IS_NULL(av_cont)) {
/* Stash away auto-viv container info. */
- if (!repr_data->auto_viv_conf)
- repr_data->auto_viv_conf = (P6opaqueAutoViv *) mem_sys_allocate_zeroed(info_alloc * sizeof(P6opaqueAutoViv));
- repr_data->auto_viv_conf[cur_avc_attr].offset = cur_size;
- repr_data->auto_viv_conf[cur_avc_attr].value = av_cont;
- cur_avc_attr++;
+ if (!repr_data->auto_viv_values)
+ repr_data->auto_viv_values = (PMC **) mem_sys_allocate_zeroed(info_alloc * sizeof(PMC *));
+ repr_data->auto_viv_values[i] = av_cont;
}
}
if (unboxed_type == STORAGE_SPEC_BP_STR) {
@@ -421,16 +418,12 @@ static PMC * get_attribute(PARROT_INTERP
}
else {
/* Maybe we know how to auto-viv it to a container. */
- if (repr_data->auto_viv_conf) {
- P6opaqueAutoViv *cur_auto_viv_conf = repr_data->auto_viv_conf;
- while (cur_auto_viv_conf->offset) {
- if (cur_auto_viv_conf->offset == repr_data->attribute_offsets[slot]) {
- PMC *value = cur_auto_viv_conf->value;
- value = REPR(value)->clone(interp, value);
- set_pmc_at_offset(instance, repr_data->attribute_offsets[slot], value);
- return value;
- }
- cur_auto_viv_conf++;
+ if (repr_data->auto_viv_values) {
+ PMC *value = repr_data->auto_viv_values[slot];
+ if (value != NULL) {
+ value = REPR(value)->clone(interp, value);
+ set_pmc_at_offset(instance, repr_data->attribute_offsets[slot], value);
+ return value;
}
}
return PMCNULL;
--- ./nqp/src/6model/reprs/P6opaque.h.orig 2011-07-11 11:06:01.000000000 +0000
+++ ./nqp/src/6model/reprs/P6opaque.h 2011-07-11 11:10:30.000000000 +0000
@@ -21,12 +21,6 @@ typedef struct {
PMC *name_map;
} P6opaqueNameMap;
-/* Represents a container that needs automatic vivification. */
-typedef struct {
- INTVAL offset;
- PMC *value;
-} P6opaqueAutoViv;
-
/* The P6opaque REPR data has the slot mapping, allocation size and
* various other bits of info. It hangs off the REPR_data pointer
* in the s-table. */
@@ -48,7 +42,7 @@ typedef struct {
/* Instantiated objects are just a blank piece of memory that needs to
* be set up. However, in some cases we'd like them to magically turn in
* to some container type. */
- P6opaqueAutoViv *auto_viv_conf;
+ PMC **auto_viv_values;
/* If we can unbox to a native integer, this is the offset to find it. */
INTVAL unbox_int_offset;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment