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

IvanHu ivan.hu at canonical.com
Wed Dec 19 05:51:15 UTC 2012


On 12/11/2012 07:14 AM, Colin King 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));
>   }
>
>   /*
>
Acked-by: Ivan Hu <ivan.hu at canonical.com>



More information about the fwts-devel mailing list