From 2036f7d3447d4e568f2736441c839678da310f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 9 Apr 2013 12:03:05 +0200 Subject: [PATCH] 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(+) create mode 100644 src/lib/eina/eina_inline_inlist.x diff --git a/ChangeLog b/ChangeLog index f9734d0b6b..2a8e558f44 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 de6a30842f..ed33eef9e8 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 d79486bba7..1080b58328 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 0000000000..f4cd95e7dd --- /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 . + */ + +#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 6a318d7992..2829967e12 100644 --- a/src/lib/eina/eina_inlist.h +++ b/src/lib/eina/eina_inlist.h @@ -579,6 +579,38 @@ EAPI Eina_Inlist *eina_inlist_promote(Eina_Inlist *list, 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. * @@ -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 7d29b37f40..46257c89b3 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);