2 Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
3 Contributed by Nathan Sidwell <nathan@codesourcery.com>
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
32 /* Calculate the new ALLOC value, making sure that abs(RESERVE) slots
33 are free. If RESERVE < 0 grow exactly, otherwise grow
36 static inline unsigned
37 calculate_allocation (const struct vec_prefix
*pfx
, int reserve
)
48 /* If there's no prefix, and we've not requested anything, then we
49 will create a NULL vector. */
52 /* We must have run out of room. */
53 gdb_assert (alloc
- num
< (unsigned)(reserve
< 0 ? -reserve
: reserve
));
57 alloc
= num
+ -reserve
;
60 /* Exponential growth. */
64 /* Double when small. */
67 /* Grow slower when large. */
68 alloc
= (alloc
* 3 / 2);
70 /* If this is still too small, set it to the right size. */
71 if (alloc
< num
+ reserve
)
72 alloc
= num
+ reserve
;
77 /* Ensure there are at least abs(RESERVE) free slots in VEC. If
78 RESERVE < 0 grow exactly, else grow exponentially. As a special
79 case, if VEC is NULL, and RESERVE is 0, no vector will be created. */
82 vec_p_reserve (void *vec
, int reserve
)
84 return vec_o_reserve (vec
, reserve
,
85 offsetof (struct vec_prefix
, vec
), sizeof (void *));
88 /* As vec_p_reserve, but for object vectors. The vector's trailing
89 array is at VEC_OFFSET offset and consists of ELT_SIZE sized
93 vec_o_reserve (void *vec
, int reserve
, size_t vec_offset
, size_t elt_size
)
95 struct vec_prefix
*pfx
= vec
;
96 unsigned alloc
= calculate_allocation (pfx
, reserve
);
101 vec
= xrealloc (vec
, vec_offset
+ alloc
* elt_size
);
102 ((struct vec_prefix
*)vec
)->alloc
= alloc
;
104 ((struct vec_prefix
*)vec
)->num
= 0;
116 typedef obj_t
*ptr_t
;
This page took 0.03209 seconds and 4 git commands to generate.