restructure
This commit is contained in:
@@ -124,12 +124,12 @@ heim_array_append_value(heim_array_t array, heim_object_t object)
|
||||
* Iterate over all objects in array
|
||||
*
|
||||
* @param array array to iterate over
|
||||
* @param fn function to call on each object
|
||||
* @param ctx context passed to fn
|
||||
* @param fn function to call on each object
|
||||
*/
|
||||
|
||||
void
|
||||
heim_array_iterate_f(heim_array_t array, heim_array_iterator_f_t fn, void *ctx)
|
||||
heim_array_iterate_f(heim_array_t array, void *ctx, heim_array_iterator_f_t fn)
|
||||
{
|
||||
size_t n;
|
||||
for (n = 0; n < array->len; n++)
|
||||
@@ -178,11 +178,11 @@ heim_array_get_length(heim_array_t array)
|
||||
*/
|
||||
|
||||
heim_object_t
|
||||
heim_array_copy_value(heim_array_t array, size_t idx)
|
||||
heim_array_get_value(heim_array_t array, size_t idx)
|
||||
{
|
||||
if (idx >= array->len)
|
||||
heim_abort("index too large");
|
||||
return heim_retain(array->val[idx]);
|
||||
return array->val[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -138,6 +138,14 @@ heim_release(void *ptr)
|
||||
heim_abort("over release");
|
||||
}
|
||||
|
||||
void
|
||||
_heim_make_permanent(heim_object_t ptr)
|
||||
{
|
||||
struct heim_base *p = PTR2BASE(ptr);
|
||||
p->ref_cnt = heim_base_atomic_max;
|
||||
}
|
||||
|
||||
|
||||
static heim_type_t tagged_isa[9] = {
|
||||
&_heim_number_object,
|
||||
&_heim_null_object,
|
||||
|
@@ -122,13 +122,13 @@ heim_tid_t heim_array_get_type_id(void);
|
||||
typedef void (*heim_array_iterator_f_t)(heim_object_t, void *);
|
||||
|
||||
int heim_array_append_value(heim_array_t, heim_object_t);
|
||||
void heim_array_iterate_f(heim_array_t, heim_array_iterator_f_t, void *);
|
||||
void heim_array_iterate_f(heim_array_t, void *, heim_array_iterator_f_t);
|
||||
#ifdef __BLOCKS__
|
||||
void heim_array_iterate(heim_array_t, void (^)(heim_object_t));
|
||||
#endif
|
||||
size_t heim_array_get_length(heim_array_t);
|
||||
heim_object_t
|
||||
heim_array_copy_value(heim_array_t, size_t);
|
||||
heim_array_get_value(heim_array_t, size_t);
|
||||
void heim_array_delete_value(heim_array_t, size_t);
|
||||
#ifdef __BLOCKS__
|
||||
void heim_array_filter(heim_array_t, int (^)(heim_object_t));
|
||||
@@ -166,6 +166,9 @@ heim_string_t heim_string_create_with_bytes(const void *, size_t);
|
||||
heim_tid_t heim_string_get_type_id(void);
|
||||
const char * heim_string_get_utf8(heim_string_t);
|
||||
|
||||
#define HSTR(_str) (__heim_string_constant("" _str ""))
|
||||
heim_string_t __heim_string_constant(const char *);
|
||||
|
||||
/*
|
||||
* Number
|
||||
*/
|
||||
|
@@ -85,6 +85,9 @@ _heim_alloc_object(heim_type_t type, size_t size);
|
||||
heim_tid_t
|
||||
_heim_type_get_tid(heim_type_t type);
|
||||
|
||||
void
|
||||
_heim_make_permanent(heim_object_t ptr);
|
||||
|
||||
/* tagged tid */
|
||||
extern struct heim_type_data _heim_null_object;
|
||||
extern struct heim_type_data _heim_bool_object;
|
||||
|
@@ -120,3 +120,40 @@ heim_string_get_utf8(heim_string_t string)
|
||||
{
|
||||
return (const char *)string;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static void
|
||||
init_string(void *ptr)
|
||||
{
|
||||
heim_dict_t *dict = ptr;
|
||||
*dict = heim_dict_create(101);
|
||||
heim_assert(*dict != NULL, "__heim_string_constant");
|
||||
}
|
||||
|
||||
heim_string_t
|
||||
__heim_string_constant(const char *_str)
|
||||
{
|
||||
static HEIMDAL_MUTEX mutex = HEIMDAL_MUTEX_INITIALIZER;
|
||||
static heim_base_once_t once;
|
||||
static heim_dict_t dict = NULL;
|
||||
heim_string_t s, s2;
|
||||
|
||||
heim_base_once_f(&once, &dict, init_string);
|
||||
s = heim_string_create(_str);
|
||||
|
||||
HEIMDAL_MUTEX_lock(&mutex);
|
||||
s2 = heim_dict_get_value(dict, s);
|
||||
if (s2) {
|
||||
heim_release(s);
|
||||
s = s2;
|
||||
} else {
|
||||
_heim_make_permanent(s);
|
||||
heim_dict_set_value(dict, s, s);
|
||||
}
|
||||
HEIMDAL_MUTEX_unlock(&mutex);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ HEIMDAL_BASE_1.0 {
|
||||
heim_abort;
|
||||
heim_alloc;
|
||||
heim_array_append_value;
|
||||
heim_array_copy_value;
|
||||
heim_array_get_value;
|
||||
heim_array_create;
|
||||
heim_array_delete_value;
|
||||
heim_array_get_length;
|
||||
|
Reference in New Issue
Block a user