pike.git/
src/
array.c
Branch:
Tag:
Non-build tags
All tags
No tags
2008-07-01
2008-07-01 09:36:29 by Martin Stjernholm <mast@lysator.liu.se>
cfd70dcd54cd26b7fc9e461baddbc1285f52ddb7 (
22
lines) (+
15
/-
7
)
[
Show
|
Annotate
]
Branch:
7.9
Avoid overallocated empty arrays.
Rev: src/array.c:1.211
Rev: src/array.h:1.76
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.
210
2008/
06
/
23
16
:
05
:
02
mast Exp $
+
|| $Id: array.c,v 1.
211
2008/
07
/
01
09
:
36
:
28
mast Exp $
*/ #include "global.h"
529:
Pike_fatal("Illegal argument to array_shrink.\n"); #endif
-
if
(size
==
v->
size
)
return
v;
-
+
/* Ensure that one of the empty arrays are returned
if size
is
zero.
*/
if( !size ) {
-
free_
array(v
);
-
/*
FIXME:
What
about
weak
markers
etc?
*/
-
add
_
ref(
&empty_array);
-
return
&empty
_array;
+
struct
array
*e =
(v
->flags & ARRAY_WEAK_FLAG ?
+
&weak
_
empty_array :
&empty_array);
+
if
(e != v) {
+
free
_array
(v)
;
+
add_ref (e);
}
-
+
return e;
+
}
-
+
if (size == v->size) return v;
+
/* Free items outside the new array. */ free_svalues(ITEM(v) + size, v->size - size, v->type_field); v->size=size;
568:
if(d_flag > 1) array_check_type_field(a); #endif
+
/* Ensure that one of the empty arrays are returned if size is zero. */
+
if (!size) return array_shrink (a, size);
+
if(a->size == size) return a; if(size > a->size) {