Jean-Christophe Dubois wrote: > just a few comments: > > On Tuesday 08 January 2008 22:42:23 Tito wrote: > >> llist_add_to(&list, memcpy(size, &i, >> sizeof(int))); >> >> llist_add_to(&list, line); >> > More generally would it make sense to define a structure holding both the > string size and the string pointer? This would allow to call llist_add_to() > only once per line instead of twice (same for llist_pop) ... > I agree that it would be more efficient to use a structure for the length and and the content of the line, for memory usage and for run time. And because llist_add_to() allocates a new llist_t element for each list element, it would use even less memory and less calls to malloc() to use a struct that contains the list pointer, the line length and the line content. It might even result in a little smaller code size. A malloc() is necessary anyways, and the code to inser an element in a single linked list may be smaller that the code to call a function to do it.
Also, "size" has been allocated with malloc(), so it should be properly aligned to be accessed as an int. Therefor memcpy(size, &i, sizeof(int)) could be written as *size = i which is better readable and most likely produces shorter code, especially on machines where unaligned writes are not possible. Regards Ralf Friedl _______________________________________________ busybox mailing list [email protected] http://busybox.net/cgi-bin/mailman/listinfo/busybox
