[PATCH] lib: fwts_list: make list creation and initialisation more optimal.

Keng-Yu Lin kengyu at canonical.com
Wed Dec 12 07:53:13 UTC 2012


On Tue, Dec 11, 2012 at 7:14 AM, Colin King <colin.king at canonical.com> wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> We can just memset() a list structure to initialise it rather than
> zero'ing individual members.  Also, when creating a new list struct
> we may as well just return the pointer from calloc() rather than
> checking for NULL and then returning NULL if calloc() failed.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/lib/src/fwts_list.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/src/lib/src/fwts_list.c b/src/lib/src/fwts_list.c
> index 935910b..0f1e8a9 100644
> --- a/src/lib/src/fwts_list.c
> +++ b/src/lib/src/fwts_list.c
> @@ -29,9 +29,7 @@
>   */
>  void fwts_list_init(fwts_list *list)
>  {
> -       list->head = NULL;
> -       list->tail = NULL;
> -       list->len = 0;
> +       memset(list, 0, sizeof(fwts_list));
>  }
>
>  /*
> @@ -40,14 +38,8 @@ void fwts_list_init(fwts_list *list)
>   */
>  fwts_list *fwts_list_new(void)
>  {
> -       fwts_list *list;
> -
> -       if ((list = calloc(1, sizeof(fwts_list))) == NULL)
> -               return NULL;
> -
> -       fwts_list_init(list);
> -
> -       return list;
> +       /* calloc already zero's the list */
> +       return calloc(1, sizeof(fwts_list));
>  }
>
>  /*
> --
> 1.8.0
>
Acked-by: Keng-Yu Lin <kengyu at canonical.com>



More information about the fwts-devel mailing list