Branch: Tag:

2019-11-22

2019-11-22 15:47:28 by Henrik Grubbström (Grubba) <grubba@grubba.org>

ADT.List: Added _reverse().

5892:    * 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.    */
6031:    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.