Re: [Vala] Redundant C code



On 08/06/10 17:27, Kentaro NAKAZAWA wrote:
Hello.
(sorry, my English is not so good ;)

When I convert the following code into C language.

----------------
void main () {
  int[] a = { };
  a += 1;
  a += 1;
}
----------------

It is converted into a redundant following C code.

----------------
static void _vala_array_add1 (gint** array, int* length, int* size, gint value) {
      if ((*length) == (*size)) {
              *size = (*size) ? (2 * (*size)) : 4;
              *array = g_renew (gint, *array, *size);
      }
      (*array)[(*length)++] = value;
}

static void _vala_array_add2 (gint** array, int* length, int* size, gint value) {
      if ((*length) == (*size)) {
              *size = (*size) ? (2 * (*size)) : 4;
              *array = g_renew (gint, *array, *size);
      }
      (*array)[(*length)++] = value;
}
----------------

I think enough by one.


I think implementing an anti-redundancy method here would not mean much
better performance at runtime in "real" programs, because you would use
a for() loop instead:

----------------
void main () {
    int[] a = { };
    for (int i=0; i<2; i++) {
        a += 1;
    }
}
----------------

And the resulting C code will have one _vala_array_add%d function only.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]