pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:5885:
/* Suggestions for future functionality: * * o Pop tail * o Join * o Copy segment * o Detach segment (requires new iterator implementation) * o Iterator copy * o _equal() for iterators. * o _search(), cast() * o _indices()??
-
* o Support for
reverse(),
filter() and map().
+
* o Support for filter() and map().
* o Initialization from array. * o Support for Pike.count_memory. */ PIKEFUN int _size_object() { int q = THIS->num_elems; int res = q * sizeof(struct pike_list_node); struct mapping *m = NULL;
pike.git/src/builtin.cmod:6024:
push_static_text("ADT.List(/* 1 element */)"); } else { push_static_text("ADT.List(/* %d elements */)"); push_int(THIS->num_elems); f_sprintf(2); } } stack_pop_n_elems_keep_top(args); }
+
/*! @decl protected List _reverse()
+
*!
+
*! Reverse the list.
+
*!
+
*! @seealso
+
*! @[reverse()]
+
*/
+
PIKEFUN List _reverse()
+
flags ID_PROTECTED;
+
{
+
struct object *res = clone_object(List_program, 0);
+
struct List_struct *other_list = get_storage(res, List_program);
+
struct pike_list_node *n;
+
struct pike_list_node *other_n;
+
push_object(res);
+
#ifdef PIKE_DEBUG
+
if (!other_list) Pike_fatal("Internal error in List::_reverse()\n");
+
#endif
+
for (n = THIS->head; n->next; n = n->next) {
+
other_n = alloc_pike_list_node();
+
assign_svalue_no_free(&other_n->val, &n->val);
+
prepend_list_node(other_list->head, other_n);
+
other_list->num_elems++;
+
free_list_node(other_n);
+
}
+
}
+
/*! @decl mixed head() *! *! Get the element at the head of the list. *! *! @throws *! Throws an error if the list is empty. *! *! @seealso *! @[is_empty()], @[tail()], @[pop()] */