[U-Boot] [PATCH v3 3/7] dfu: DFU backend implementation

Mike Frysinger vapier at gentoo.org
Sat Aug 4 18:28:27 CEST 2012


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: <http://lists.denx.de/pipermail/u-boot/attachments/20120804/bc42c593/attachment.pgp>


More information about the U-Boot mailing list