2008-08-06 11:15:24 -07:00
|
|
|
/* EINA - EFL data type library
|
|
|
|
* Copyright (C) 2008 Cedric Bail
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-08-06 08:42:33 -07:00
|
|
|
#ifndef EINA_INLINE_ARRAY_X_
|
|
|
|
#define EINA_INLINE_ARRAY_X_
|
2008-07-30 09:34:54 -07:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
# define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
|
|
|
#else
|
|
|
|
# define UNLIKELY(x) (x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline Eina_Bool
|
2008-08-08 07:25:37 -07:00
|
|
|
eina_array_grow(Eina_Array *array)
|
2008-07-30 09:34:54 -07:00
|
|
|
{
|
|
|
|
void **tmp;
|
2008-08-01 05:26:35 -07:00
|
|
|
unsigned int total;
|
|
|
|
|
2008-07-30 09:34:54 -07:00
|
|
|
total = array->total + array->step;
|
|
|
|
tmp = realloc(array->data, sizeof (void*) * total);
|
2008-08-01 05:26:35 -07:00
|
|
|
if (UNLIKELY(!tmp)) return 0;
|
|
|
|
|
2008-07-30 09:34:54 -07:00
|
|
|
array->total = total;
|
|
|
|
array->data = tmp;
|
2008-08-01 05:26:35 -07:00
|
|
|
|
2008-07-30 09:34:54 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2008-08-13 02:24:49 -07:00
|
|
|
eina_array_append(Eina_Array *array, const void *data)
|
2008-07-30 09:34:54 -07:00
|
|
|
{
|
|
|
|
if (UNLIKELY((array->count + array->step) > array->total))
|
2008-08-08 07:25:37 -07:00
|
|
|
if (!eina_array_grow(array)) return ;
|
2008-08-01 05:26:35 -07:00
|
|
|
|
2008-08-13 02:24:49 -07:00
|
|
|
array->data[array->count++] = (void*) data;
|
2008-07-30 09:34:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
2008-08-11 09:21:19 -07:00
|
|
|
eina_array_get(const Eina_Array *array, unsigned int index)
|
2008-07-30 09:34:54 -07:00
|
|
|
{
|
|
|
|
return array->data[index];
|
|
|
|
}
|
|
|
|
|
2008-08-01 05:26:35 -07:00
|
|
|
static inline unsigned int
|
2008-08-11 09:21:19 -07:00
|
|
|
eina_array_count(const Eina_Array *array)
|
2008-08-01 05:26:35 -07:00
|
|
|
{
|
|
|
|
return array->count;
|
|
|
|
}
|
|
|
|
|
2008-07-30 09:34:54 -07:00
|
|
|
#endif
|