I don't see the point of eina_inlist_last given that last is part of the
inlist struct.


On Tue, Apr 9, 2013 at 11:01 AM, Jérémy Zurcher - Enlightenment Git <
no-re...@enlightenment.org> wrote:

> jeyzu pushed a commit to branch master.
>
> commit 2036f7d3447d4e568f2736441c839678da310f22
> Author: Jérémy Zurcher <jer...@asynk.ch>
> Date:   Tue Apr 9 12:03:05 2013 +0200
>
>     eina: add eina_inlist_first and eina_inlist_last
>
>        - both as static inline functions
>        - test added in eina_inlist_simple
> ---
>  ChangeLog                         |  4 ++++
>  NEWS                              |  2 ++
>  src/Makefile_Eina.am              |  1 +
>  src/lib/eina/eina_inline_inlist.x | 46
> +++++++++++++++++++++++++++++++++++++++
>  src/lib/eina/eina_inlist.h        | 34 +++++++++++++++++++++++++++++
>  src/tests/eina/eina_test_inlist.c |  6 +++++
>  6 files changed, 93 insertions(+)
>
> diff --git a/ChangeLog b/ChangeLog
> index f9734d0..2a8e558 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,7 @@
> +2013-04-09  Jérémy Zurcher (jeyzu)
> +
> +        * Eina: Add eina_inlist_first and eina_inlist_last
> +
>  2013-04-08  Tom Hacohen
>
>          * Evas font: Fix a bug with cluster size calculation with texts
> ending
> diff --git a/NEWS b/NEWS
> index de6a308..ed33eef 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -23,6 +23,8 @@ Additions:
>       - Add eina_list_shuffle()
>       - Add eina_file_mkstemp()
>       - Add eina_log_timing()
> +     - Add eina_inlist_first
> +     - Add eina_inlist_last
>      * Add Cserve2 scalecache support
>      * ecore_x:
>       - Add window profile support.
> diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am
> index d79486b..1080b58 100644
> --- a/src/Makefile_Eina.am
> +++ b/src/Makefile_Eina.am
> @@ -26,6 +26,7 @@ lib/eina/eina_clist.h \
>  lib/eina/eina_inline_clist.x \
>  lib/eina/eina_inarray.h \
>  lib/eina/eina_inlist.h \
> +lib/eina/eina_inline_inlist.x \
>  lib/eina/eina_list.h \
>  lib/eina/eina_file.h \
>  lib/eina/eina_mempool.h \
> diff --git a/src/lib/eina/eina_inline_inlist.x
> b/src/lib/eina/eina_inline_inlist.x
> new file mode 100644
> index 0000000..f4cd95e
> --- /dev/null
> +++ b/src/lib/eina/eina_inline_inlist.x
> @@ -0,0 +1,46 @@
> +/* EINA - EFL data type library
> + * Copyright (C) 2013 Jérémy Zurcher
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library;
> + * if not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef EINA_INLIST_INLINE_H_
> +#define EINA_INLIST_INLINE_H_
> +
> +static inline Eina_Inlist *
> +eina_inlist_first(const Eina_Inlist *list)
> +{
> +   Eina_Inlist *l;
> +
> +   if (!list) return NULL;
> +
> +   for (l = (Eina_Inlist*)list; l->prev; l = l->prev);
> +
> +   return l;
> +}
> +
> +static inline Eina_Inlist *
> +eina_inlist_last(const Eina_Inlist *list)
> +{
> +   Eina_Inlist *l;
> +
> +   if (!list) return NULL;
> +
> +   for (l = (Eina_Inlist*)list; l->next; l = l->next);
> +
> +   return l;
> +}
> +
> +#endif /* EINA_INLIST_INLINE_H_ */
> diff --git a/src/lib/eina/eina_inlist.h b/src/lib/eina/eina_inlist.h
> index 6a318d7..2829967 100644
> --- a/src/lib/eina/eina_inlist.h
> +++ b/src/lib/eina/eina_inlist.h
> @@ -580,6 +580,38 @@ EAPI Eina_Inlist   *eina_inlist_demote(Eina_Inlist
> *list,
>                                         Eina_Inlist *item)
> EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
>
>  /**
> + * @brief Get the first list node in the list.
> + *
> + * @param list The list to get the first list node from.
> + * @return The first list node in the list.
> + *
> + * This function returns the first list node in the list @p list. If
> + * @p list is @c NULL, @c NULL is returned.
> + *
> + * This is a O(N) operation (it takes time proportional
> + * to the length of the list).
> + *
> + * @since 1.8
> + */
> +static inline Eina_Inlist *eina_inlist_first(const Eina_Inlist *list)
> EINA_PURE EINA_WARN_UNUSED_RESULT;
> +
> +/**
> + * @brief Get the last list node in the list.
> + *
> + * @param list The list to get the last list node from.
> + * @return The last list node in the list.
> + *
> + * This function returns the last list node in the list @p list. If
> + * @p list is @c NULL, @c NULL is returned.
> + *
> + * This is a O(N) operation (it takes time proportional
> + * to the length of the list).
> + *
> + * @since 1.8
> + */
> +static inline Eina_Inlist *eina_inlist_last(const Eina_Inlist *list)
> EINA_PURE EINA_WARN_UNUSED_RESULT;
> +
> +/**
>   * @brief Get the count of the number of items in a list.
>   *
>   * @param list The list whose count to return.
> @@ -825,6 +857,8 @@ EAPI Eina_Inlist *eina_inlist_sort(Eina_Inlist *head,
> Eina_Compare_Cb func);
>    for (it = NULL, it = (list ? _EINA_INLIST_CONTAINER(it, list->last) :
> NULL); \
>         it; it = (EINA_INLIST_GET(it)->prev ? _EINA_INLIST_CONTAINER(it,
> EINA_INLIST_GET(it)->prev) : NULL))
>
> +#include "eina_inline_inlist.x"
> +
>  /**
>   * @}
>   */
> diff --git a/src/tests/eina/eina_test_inlist.c
> b/src/tests/eina/eina_test_inlist.c
> index 7d29b37..46257c8 100644
> --- a/src/tests/eina/eina_test_inlist.c
> +++ b/src/tests/eina/eina_test_inlist.c
> @@ -86,6 +86,7 @@ _eina_test_inlist_build(int i)
>  START_TEST(eina_inlist_simple)
>  {
>     Eina_Inlist *lst = NULL;
> +   Eina_Inlist *tmpl = NULL;
>     Eina_Test_Inlist *tmp;
>     Eina_Test_Inlist *prev;
>     int i = 0;
> @@ -285,6 +286,11 @@ START_TEST(eina_inlist_simple)
>     lst = bkp;
>  #endif
>
> +   tmpl = eina_inlist_last(lst);
> +   fail_if(tmpl == lst);
> +   tmpl = eina_inlist_first(tmpl);
> +   fail_if(tmpl != lst);
> +
>     tmp = EINA_INLIST_CONTAINER_GET(lst, Eina_Test_Inlist);
>     lst = eina_inlist_demote(lst, lst);
>     fail_if(EINA_INLIST_CONTAINER_GET(lst, Eina_Test_Inlist) == tmp);
>
> --
>
>
> ------------------------------------------------------------------------------
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to