eina: add eina_inlist_first and eina_inlist_last

- both as static inline functions
   - test added in eina_inlist_simple
This commit is contained in:
Jérémy Zurcher 2013-04-09 12:03:05 +02:00
parent a1e0190725
commit 2036f7d344
6 changed files with 93 additions and 0 deletions

View File

@ -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

2
NEWS
View File

@ -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.

View File

@ -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 \

View File

@ -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_ */

View File

@ -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"
/**
* @}
*/

View File

@ -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);