fx.collections: update iterator semantics
This commit is contained in:
@@ -17,7 +17,7 @@ struct fx_array_p {
|
||||
};
|
||||
|
||||
struct fx_array_iterator_p {
|
||||
fx_array *_a;
|
||||
const fx_array *_a;
|
||||
struct fx_array_p *_a_p;
|
||||
|
||||
/** The index of the current value */
|
||||
@@ -170,9 +170,7 @@ static fx_value array_get(struct fx_array_p *array, size_t at)
|
||||
return FX_VALUE_EMPTY;
|
||||
}
|
||||
|
||||
fx_value result;
|
||||
fx_value_copy(&result, &array->ar_data[at]);
|
||||
return result;
|
||||
return fx_value_copy_return(array->ar_data[at]);
|
||||
}
|
||||
|
||||
static size_t array_get_size(const struct fx_array_p *array)
|
||||
@@ -373,7 +371,7 @@ static fx_status array_to_string(
|
||||
|
||||
/*** ITERATOR FUNCTIONS *******************************************************/
|
||||
|
||||
static fx_iterator *iterable_begin(fx_object *obj)
|
||||
static const fx_iterator *iterable_begin(const fx_object *obj)
|
||||
{
|
||||
fx_array_iterator *it_obj = fx_object_create(FX_TYPE_ARRAY_ITERATOR);
|
||||
struct fx_array_iterator_p *it = fx_object_get_private(
|
||||
@@ -437,7 +435,7 @@ static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_value iterator_get_value(const fx_iterator *obj)
|
||||
static const fx_value *iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_array_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
@@ -445,10 +443,10 @@ static fx_value iterator_get_value(const fx_iterator *obj)
|
||||
struct fx_array_p *array = it->_a_p;
|
||||
|
||||
if (it->i >= array->ar_len) {
|
||||
return FX_VALUE_EMPTY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return *it->value;
|
||||
return it->value;
|
||||
}
|
||||
|
||||
static enum fx_status iterator_is_valid(const fx_iterator *obj)
|
||||
|
||||
Reference in New Issue
Block a user