Re: [Gccpy-devel] [PATCH] struct gpy_object_list: remove the "length" attribute.
Python Front-end to GCC
Brought to you by:
redbrain812
|
From: Philip H. <red...@gc...> - 2013-05-21 19:15:01
|
Looks like a good idea, are you considering moving to a new list
implementation aswell? I will apply this patch makes a lot more sense. I am
working on adding more documentation to the wiki but its going slow.
--Phil
On 21 May 2013 11:56, Cyril Roelandt <tip...@gm...> wrote:
> We do not want to store the length of a list in both the length attribute
> and
> enclosure->length.
> ---
> libgpython/runtime/gpy-object-list.c | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/libgpython/runtime/gpy-object-list.c
> b/libgpython/runtime/gpy-object-list.c
> index b0e0a02..32e09a9 100644
> --- a/libgpython/runtime/gpy-object-list.c
> +++ b/libgpython/runtime/gpy-object-list.c
> @@ -29,7 +29,6 @@ along with GCC; see the file COPYING3. If not see
> #include <gpython/runtime.h>
>
> struct gpy_object_list {
> - int length;
> gpy_vector_t * enclosure;
> };
>
> @@ -46,7 +45,6 @@ gpy_object_t * gpy_obj_list_new (gpy_typedef_t * type,
>
> struct gpy_object_list * self = (struct gpy_object_list *)
> gpy_malloc (sizeof (struct gpy_object_list));
> - self->length = len;
>
> self->enclosure = (struct gpy_vector_t *)
> gpy_malloc (sizeof (gpy_vector_t));
> @@ -119,7 +117,10 @@ gpy_obj_list_add (gpy_object_t * o1, gpy_object_t *
> o2)
> struct gpy_object_list * l1 = (struct gpy_object_list *) x->state;
> struct gpy_object_list * l2 = (struct gpy_object_list *) y->state;
>
> - int n = l1->length + l2->length;
> + gpy_vector_t * vec1 = l1->enclosure;
> + gpy_vector_t * vec2 = l2->enclosure;
> +
> + int n = vec1->length + vec2->length;
>
> gpy_object_t ** elems = (gpy_object_t **)
> gpy_calloc (n+1, sizeof (gpy_object_t *));
> @@ -128,11 +129,10 @@ gpy_obj_list_add (gpy_object_t * o1, gpy_object_t *
> o2)
> for (i = 0; i < n; ++i)
> {
> gpy_object_state_t * x = o1->o.object_state;
> - if (i < l1->length)
> - elems[i] = GPY_VEC_index (gpy_object_t *, l1->enclosure, i);
> + if (i < vec1->length)
> + elems[i] = GPY_VEC_index (gpy_object_t *, vec1, i);
> else
> - elems[i] = GPY_VEC_index (gpy_object_t *, l2->enclosure,
> - i - l1->length);
> + elems[i] = GPY_VEC_index (gpy_object_t *, vec2, i - vec1->length);
> }
> elems [n] = NULL;
>
> @@ -190,8 +190,9 @@ gpy_obj_list_eval_bool (gpy_object_t * x)
> bool retval = false;
> gpy_object_state_t * t = x->o.object_state;
> struct gpy_object_list * state = (struct gpy_object_list *) t->state;
> + gpy_vector_t * vec = state->enclosure;
>
> - if (state->length != 0)
> + if (vec->length != 0)
> retval = true;
>
> return retval;
> --
> 1.7.10.4
>
>
>
> ------------------------------------------------------------------------------
> Try New Relic Now & We'll Send You this Cool Shirt
> New Relic is the only SaaS-based application performance monitoring service
> that delivers powerful full stack analytics. Optimize and monitor your
> browser, app, & servers with just a few lines of code. Try New Relic
> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
> _______________________________________________
> Gccpy-devel mailing list
> Gcc...@li...
> https://lists.sourceforge.net/lists/listinfo/gccpy-devel
>
|