After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 621220 - Redundant C code when appending to array
Redundant C code when appending to array
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Arrays
unspecified
Other All
: Low minor
: ---
Assigned To: Vala maintainers
Vala maintainers
: 622145 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-06-10 16:21 UTC by Kentaro NAKAZAWA
Modified: 2018-05-22 13:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Don't generate duplicate dop/copy/add code (8.47 KB, patch)
2011-05-12 19:56 UTC, geert jordaens
none Details | Review
Patch to remove duplicated wrappers (16.40 KB, patch)
2011-05-13 19:38 UTC, geert jordaens
none Details | Review
A short patch to fix this. (1.14 KB, patch)
2011-06-17 17:47 UTC, Jacques-Pascal Deplaix
none Details | Review
A short patch to fix it (Not buggy version) (1.87 KB, patch)
2011-06-17 19:52 UTC, Jacques-Pascal Deplaix
none Details | Review

Description Kentaro NAKAZAWA 2010-06-10 16:21:17 UTC
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.
Comment 1 Jürg Billeter 2010-06-16 20:07:02 UTC
Confirming but it's mostly a cosmetic issue.
Comment 2 Luca Bruno 2010-06-20 08:07:02 UTC
*** Bug 622145 has been marked as a duplicate of this bug. ***
Comment 3 geert jordaens 2011-05-12 19:56:28 UTC
Created attachment 187735 [details] [review]
Don't generate duplicate dop/copy/add code

Only generate dup/copy/add code for distinct parameter list.
Comment 4 Luca Bruno 2011-05-12 20:22:48 UTC
Review of attachment 187735 [details] [review]:

Why is next_array_*_id still needed if we use the hashmap?
Comment 5 geert jordaens 2011-05-12 21:50:28 UTC
To generate a distinct name for each distinct parameter list.
Comment 6 Luca Bruno 2011-05-13 10:44:49 UTC
(In reply to comment #5)
> To generate a distinct name for each distinct parameter list.

I don't see anything discriminating parameters in your patch that need that index, what am I missing? Can you provide a case where I can see _copy_wrapper2?
Comment 7 geert jordaens 2011-05-13 15:44:06 UTC
void main () {
  int[] a = { };
  double[] b = { };
  a += 1;
  a += 1;
  b += 1.0;
  b += 1.0;
}
Comment 8 Luca Bruno 2011-05-13 16:05:07 UTC
Oh, indeed I somehow read in the patch you were using the hash to get the function name as well, I was wrong sorry.
I think it is sane enough to not use the type cname because of possible pointers/clashes. We should use this method in other parts of the codegen as well.
What about using right the type cname as hash rather than concatenating _vala_array_* at this point, if I'm not missing anything again?
Comment 9 Luca Bruno 2011-05-13 16:08:31 UTC
Alternatively, we can keep concatenating "_vala_array_add" and take advantage of add_wrapper rather than creating new hashmaps, which I think better suits the current code.
Comment 10 geert jordaens 2011-05-13 19:38:09 UTC
Created attachment 187787 [details] [review]
Patch to remove duplicated wrappers

modify add_wrapper

 codegen/valaccodearraymodule.vala      |   97 ++++++++++++++++++++------------
 codegen/valaccodebasemodule.vala       |   40 +++++++++-----
 codegen/valaccodedelegatemodule.vala   |    2 +-
 codegen/valaccodemethodcallmodule.vala |    2 +-
 codegen/valagasyncmodule.vala          |    4 +-
 codegen/valagdbusservermodule.vala     |    2 +-
Comment 11 Jacques-Pascal Deplaix 2011-06-17 17:47:57 UTC
Created attachment 190144 [details] [review]
A short patch to fix this.
Comment 12 Jacques-Pascal Deplaix 2011-06-17 18:47:06 UTC
Oh sorry, I wrote too much soon. My patch is buggy !

I'll fix that.
Comment 13 Jacques-Pascal Deplaix 2011-06-17 19:52:42 UTC
Created attachment 190152 [details] [review]
A short patch to fix it (Not buggy version)

Tested successfully !
Comment 14 GNOME Infrastructure Team 2018-05-22 13:37:31 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/105.