pike.git/
src/
array.c
Branch:
Tag:
Non-build tags
All tags
No tags
2006-02-19
2006-02-19 18:29:25 by Martin Nilsson <mani@lysator.liu.se>
93d4a10899acda16882233c756cf39d0a46f1a51 (
17
lines) (+
13
/-
4
)
[
Show
|
Annotate
]
Branch:
7.9
Minor refactoring of array_shrink
Rev: src/array.c:1.185
2:
|| This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: array.c,v 1.
184
2005
/
12
/
04
18:
57
:
23
nilsson Exp $
+
|| $Id: array.c,v 1.
185
2006
/
02
/
19
18:
29
:
25
nilsson Exp $
*/ #include "global.h"
443:
Pike_fatal("Illegal argument to array_shrink.\n"); #endif
-
if(!size
|| (size*4 < v->malloced_size + 4
)
) /* Should we realloc it? */
+
if(
!size )
{
-
+
free_array(v);
+
add_ref(&empty_array);
+
return &empty_array;
+
}
+
+
/* Free items outside the new array. */
+
free_svalues(ITEM(v) + size, v->size - size, v->type_field);
+
+
if(size*4 < v->malloced_size + 4) /* Should we realloc it? */
+
{
a = array_set_flags(allocate_array_no_init(size, 0), v->flags); if (a->size) { a->type_field = v->type_field; }
-
free_svalues(ITEM(v) + size, v->size - size, v->type_field);
+
MEMCPY(ITEM(a), ITEM(v), size*sizeof(struct svalue)); v->size=0; free_array(v); return a; }else{
-
free_svalues(ITEM(v) + size, v->size - size, v->type_field);
+
v->size=size; return v; }