[PATCH] dpkg: create_list: zero terminate list in loop
Robert P. J. Day
rpjday at crashcourse.ca
Thu Jun 5 11:56:48 UTC 2008
On Thu, 5 Jun 2008, Peter Korsgaard wrote:
> From: Peter Korsgaard <jacmet at sunsite.dk>
>
> Saves a few bytes:
>
> function old new delta
> create_list 124 103 -21
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-21) Total: -21 bytes
> ---
> archival/dpkg.c | 8 ++------
> 1 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/archival/dpkg.c b/archival/dpkg.c
> index 1280ca0..5bc64d5 100644
> --- a/archival/dpkg.c
> +++ b/archival/dpkg.c
> @@ -1164,15 +1164,11 @@ static char **create_list(const char *filename)
>
> while ((line = xmalloc_fgetline(list_stream)) != NULL) {
> file_list = xrealloc(file_list, sizeof(char *) * (count + 2));
> - file_list[count] = line;
> - count++;
> + file_list[count++] = line;
> + file_list[count] = NULL;
> }
> fclose(list_stream);
>
> - if (count == 0) {
> - return NULL;
> - }
> - file_list[count] = NULL;
> return file_list;
> }
you know, even though that saves a few bytes, i'd be tempted not to do
it that way since it's just plain inefficient in terms of machine
cycles -- constantly assigning NULL only to overwrite it during the
next iteration.
IMHO, not worth the saved bytes to torture the logic that way.
rday
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.
http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================
More information about the busybox
mailing list