On Tue, Jan 09, 2018 at 01:27:48PM +0100, Julia Lawall wrote: > > > +struct srcpos * > > > +srcpos_copy_all(struct srcpos *pos) > > > +{ > > > + struct srcpos *pos_new; > > > + struct srcfile_state *srcfile_state; > > > + > > > + if (!pos) > > > + return NULL; > > > + > > > + pos_new = srcpos_copy(pos); > > > + > > > + if (pos_new) { > > > + /* allocate without free */ > > > + srcfile_state = xmalloc(sizeof(struct srcfile_state)); > > > + memcpy(srcfile_state, pos->file, sizeof(struct srcfile_state)); > > > + > > > + pos_new->file = srcfile_state; > > > + } > > > + > > > + return pos_new; > > > +} > > > > I don't really see a reason we'd need both a deep and a shallow copy. > > If you need a deep copy, I'd suggest just changing srcpos_copy() to do > > that. > > The deep copy is needed due to the treatment of #includes. The following > function overwrites the file name information: > > void srcpos_set_line(char *f, int l) > { > current_srcfile->name = f; > current_srcfile->lineno = l; > } > > srcpos_combine doesn't need to use the deep copy, because the result gets > copied again. Maybe this is not a big issue or there is a better way to > solve this. Well, dtbs are generally so small that performance really isn't an issue for dtc. So I think simplifying the code to only have one (deep) copy routine is worth more than the minor speedup from avoiding deep copies in some places they're not necessary. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Attachment:
signature.asc
Description: PGP signature