From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Frysinger Date: Sat, 4 Aug 2012 12:28:27 -0400 Subject: [U-Boot] [PATCH v3 3/7] dfu: DFU backend implementation In-Reply-To: <201208040947.34852.marex@denx.de> References: <1341308291-14663-1-git-send-email-l.majewski@samsung.com> <201208031919.15373.vapier@gentoo.org> <201208040947.34852.marex@denx.de> Message-ID: <201208041230.29754.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Saturday 04 August 2012 03:47:34 Marek Vasut wrote: > Dear Mike Frysinger, > > On Thursday 02 August 2012 09:55:24 Lukasz Majewski wrote: > > > Dear Mike Frysinger, > > > > On Tuesday 31 July 2012 02:36:59 Lukasz Majewski wrote: > > > > > +int dfu_config_entities(char *env, char *interface, int num) > > > > > +{ > > > > > + struct dfu_entity *dfu; > > > > > + int i, ret; > > > > > + char *s; > > > > > + > > > > > + dfu_alt_num = dfu_find_alt_num(env); > > > > > + debug("%s: dfu_alt_num=%d\n", __func__, dfu_alt_num); > > > > > + > > > > > + for (i = 0; i < dfu_alt_num; i++) { > > > > > + dfu = calloc(sizeof(struct dfu_entity), 1); > > > > > > > > seems like you can do this in a single call outside of the for loop: > > > > dfu = calloc(sizeof(*dfu), dfu_alt_num); > > > > if (!dfu) > > > > > > > > return -1; > > > > > > > > for (i = 0; i < dfu_alt_num; i++) { > > > > > > > > s = strsep(&env, ";"); > > > > ret = dfu_fill_entity(&dfu[i], s, i, interface, num); > > > > if (ret) > > > > > > > > return -1; > > > > > > > > list_add_tail(&dfu[i].list, &dfu_list); > > > > > > > > } > > > > > > I'd prefer to leave it as it is (since IMHO is more readable) with the > > > > > addition of following code: > > it might be more slightly more readable, but doing a single function call > > results in better runtime performance > > Doesn't the compiler optimize it as it sees fit? gcc can't know to optimize malloc calls like this -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. URL: