Re: [PATCH 2/5] add ptr_list_empty()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 24/07/18 21:34, Luc Van Oostenryck wrote:
> Sometimes it's needed to know if a list is empty, for example,
> to know if a pseudo has some users or not. Currently this is
> done using ptr_list_size() which needs to walk the whole list
> while this is often not needed if the list is empty.

Sometimes we need to know if a list is empty, for example, in
order to determine if a pseudo has some users or not. Currently,
this is done using ptr_list_size(), which always walks the whole
list. It is often possible to short-circuit this walk when the
list is empty.

(or something like that! - you may have noticed that I am not
that good at writing commit messages :D ).

> 
> Add the helper ptr_list_empty() and use it for has_users().
> 
> This gives a speedup up to 18% on some pathological workloads.
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> ---
>  linearize.h |  7 ++++++-
>  ptrlist.c   | 19 +++++++++++++++++++
>  ptrlist.h   |  2 ++
>  simplify.c  |  2 +-
>  4 files changed, 28 insertions(+), 2 deletions(-)
> 
> diff --git a/linearize.h b/linearize.h
> index 092e1ac23..de42e718d 100644
> --- a/linearize.h
> +++ b/linearize.h
> @@ -333,9 +333,14 @@ static inline int pseudo_user_list_size(struct pseudo_user_list *list)
>  	return ptr_list_size((struct ptr_list *)list);
>  }
>  
> +static inline bool pseudo_user_list_empty(struct pseudo_user_list *list)
> +{
> +	return ptr_list_empty((struct ptr_list *)list);
> +}
> +
>  static inline int has_users(pseudo_t p)
>  {
> -	return pseudo_user_list_size(p->users) != 0;
> +	return !pseudo_user_list_empty(p->users);
>  }
>  
>  static inline struct pseudo_user *alloc_pseudo_user(struct instruction *insn, pseudo_t *pp)
> diff --git a/ptrlist.c b/ptrlist.c
> index 234433033..40a671000 100644
> --- a/ptrlist.c
> +++ b/ptrlist.c
> @@ -36,6 +36,25 @@ int ptr_list_size(struct ptr_list *head)
>  	return nr;
>  }
>  
> +///
> +// test if a list is empty
> +// @head: the head of the list
> +// @return: ``true`` if the list is empty, '``false`` otherwise.

extraneous ' mark just before ``false``?

ATB,
Ramsay Jones
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux