On Thu, Feb 10, 2022 at 2:13 PM Ron Yorston <r...@pobox.com> wrote:
> Use a generic llist_t to store the names of hardlinked files.
>
> function                                             old     new   delta
> cpio_o                                              1140    1122     -18
>
> Signed-off-by: Ron Yorston <r...@pobox.com>
> ---
>  archival/cpio.c | 18 ++++--------------
>  1 file changed, 4 insertions(+), 14 deletions(-)
>
> diff --git a/archival/cpio.c b/archival/cpio.c
> index 7149782d7..836609fc3 100644
> --- a/archival/cpio.c
> +++ b/archival/cpio.c
> @@ -223,13 +223,9 @@ static off_t cpio_pad4(off_t size)
>   * It's ok to exit instead of return. */
>  static NOINLINE int cpio_o(void)
>  {
> -       struct name_s {
> -               struct name_s *next;
> -               char name[1];
> -       };
>         struct inodes_s {
>                 struct inodes_s *next;
> -               struct name_s *names;
> +               llist_t *names;
>                 struct stat st;
>  #if ENABLE_FEATURE_CPIO_RENUMBER_INODES
>                 ino_t mapped_inode;
> @@ -277,7 +273,6 @@ static NOINLINE int cpio_o(void)
>
>                         /* Store hardlinks for later processing, dont output 
> them */
>                         if (!S_ISDIR(st.st_mode) && st.st_nlink > 1) {
> -                               struct name_s *n;
>                                 struct inodes_s *l;
>
>                                 /* Do we have this hardlink remembered? */
> @@ -302,11 +297,7 @@ static NOINLINE int cpio_o(void)
>                                         l = l->next;
>                                 }
>                                 /* Add new name to "l->names" list */
> -                               n = xmalloc(sizeof(*n) + strlen(name));
> -                               strcpy(n->name, name);
> -                               n->next = l->names;
> -                               l->names = n;
> -
> +                               llist_add_to(&l->names, xstrdup(name));

This is less space-efficient. Old code uses one allocation,
new one uses two.
We can potentially have a lot of hardlinks...
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to