diff --git a/src/array.c b/src/array.c
index 112b235382b46dba8cc848d035340a10581c50cb..29e4bda2116718a07a22008f0e484c51a3e59bcd 100644
--- a/src/array.c
+++ b/src/array.c
@@ -2625,43 +2625,30 @@ PMOD_EXPORT void apply_array(struct array *a, INT32 args, int flags)
 
   if (!(cycl = (struct array *)BEGIN_CYCLIC(a, (ptrdiff_t)hash))) {
     TYPE_FIELD new_types = 0;
+    struct array *aa;
     if ((flags & 1) && (a->refs == 1)) {
       /* Destructive operation possible. */
-      ref_push_array(a);
-      a->type_field |= BIT_UNFINISHED;
-      for (e=0; e < a->size; e++)
-      {
-	assign_svalues_no_free(Pike_sp, argp, args, BIT_MIXED);
-	Pike_sp+=args;
-	/* FIXME: Don't throw apply errors from apply_svalue here. */
-	apply_svalue(ITEM(a)+e,args);
-	new_types |= 1 << TYPEOF(Pike_sp[-1]);
-	assign_svalue(ITEM(a)+e, &Pike_sp[-1]);
-	pop_stack();
-      }
-      a->type_field = new_types;
-#ifdef PIKE_DEBUG
-      array_check_type_field(a);
-#endif
+      add_ref(aa = a);
+      aa->type_field |= BIT_UNFINISHED;
     } else {
-      struct array *aa;
-      push_array(aa = allocate_array_no_init(0, a->size));
-      for (e=0; (e<a->size) && (e < aa->malloced_size); e++)
-      {
-	assign_svalues_no_free(Pike_sp, argp, args, BIT_MIXED);
-	Pike_sp+=args;
-	/* FIXME: Don't throw apply errors from apply_svalue here. */
-	apply_svalue(ITEM(a)+e,args);
-	new_types |= 1 << TYPEOF(Pike_sp[-1]);
-	assign_svalue_no_free(ITEM(aa)+e, &Pike_sp[-1]);
-	aa->size = e+1;
-	pop_stack();
-      }
-      aa->type_field = new_types;
+      aa = allocate_array(a->size);
+    }
+    SET_CYCLIC_RET(aa);
+    push_array(aa);
+    for (e=0; e < a->size; e++)
+    {
+      assign_svalues_no_free(Pike_sp, argp, args, BIT_MIXED);
+      Pike_sp+=args;
+      /* FIXME: Don't throw apply errors from apply_svalue here. */
+      apply_svalue(ITEM(a)+e, args);
+      new_types |= 1 << TYPEOF(Pike_sp[-1]);
+      assign_svalue(ITEM(aa)+e, &Pike_sp[-1]);
+      pop_stack();
+    }
+    aa->type_field = new_types;
 #ifdef PIKE_DEBUG
-      array_check_type_field(aa);
+    array_check_type_field(aa);
 #endif
-    }
     stack_pop_n_elems_keep_top(args);
   }
   else {