Commit efb7e1e0 by Ian Lance Taylor Committed by Ian Lance Taylor

vec.h (VEC_reserve_exact): Define.

./:	* vec.h (VEC_reserve_exact): Define.
	(vec_gc_p_reserve_exact): Declare.
	(vec_gc_o_reserve_exact): Declare.
	(vec_heap_p_reserve_exact): Declare.
	(vec_heap_o_reserve_exact): Declare.
	(VEC_OP (T,A,reserve_exact)): New static inline function, three
	versions.
	(VEC_OP (T,A,reserve)) [all versions]: Remove handling of
	negative parameter.
	(VEC_OP (T,A,alloc)) [all versions]: Call ...reserve_exact.
	(VEC_OP (T,A,copy)) [all versions]: Likewise.
	(VEC_OP (T,a,safe_grow)) [all versions]: Likewise.
	* vec.c (calculate_allocation): Add exact parameter.  Change all
	callers.
	(vec_gc_o_reserve_1): New static function, from vec_gc_o_reserve.
	(vec_gc_p_reserve, vec_gc_o_reserve): Call vec_gc_o_reserve_1.
	(vec_gc_p_reserve_exact, vec_gc_o_reserve_exact): New functions.
	(vec_heap_o_reserve_1): New static function, from vec_heap_o_reserve.
	(vec_heap_p_reserve, vec_heap_o_reserve): Call vec_heap_o_reserve_1.
	(vec_heap_p_reserve_exact): New function.
	(vec_heap_o_reserve_exact): New function.
cp/:
	* class.c (add_method): Call VEC_reserve_exact rather than passing
	a negative size to VEC_reserve.

From-SVN: r120861
parent 9dd8004e
2007-01-17 Ian Lance Taylor <iant@google.com>
* vec.h (VEC_reserve_exact): Define.
(vec_gc_p_reserve_exact): Declare.
(vec_gc_o_reserve_exact): Declare.
(vec_heap_p_reserve_exact): Declare.
(vec_heap_o_reserve_exact): Declare.
(VEC_OP (T,A,reserve_exact)): New static inline function, three
versions.
(VEC_OP (T,A,reserve)) [all versions]: Remove handling of
negative parameter.
(VEC_OP (T,A,alloc)) [all versions]: Call ...reserve_exact.
(VEC_OP (T,A,copy)) [all versions]: Likewise.
(VEC_OP (T,a,safe_grow)) [all versions]: Likewise.
* vec.c (calculate_allocation): Add exact parameter. Change all
callers.
(vec_gc_o_reserve_1): New static function, from vec_gc_o_reserve.
(vec_gc_p_reserve, vec_gc_o_reserve): Call vec_gc_o_reserve_1.
(vec_gc_p_reserve_exact, vec_gc_o_reserve_exact): New functions.
(vec_heap_o_reserve_1): New static function, from vec_heap_o_reserve.
(vec_heap_p_reserve, vec_heap_o_reserve): Call vec_heap_o_reserve_1.
(vec_heap_p_reserve_exact): New function.
(vec_heap_o_reserve_exact): New function.
2007-01-17 Jan Hubicka <jh@suse.cz>
* ipa-type-escape.c (look_for_casts): Revamp using handled_component_p.
......
2007-01-17 Ian Lance Taylor <iant@google.com>
* class.c (add_method): Call VEC_reserve_exact rather than passing
a negative size to VEC_reserve.
2007-01-11 Simon Martin <simartin@users.sourceforge.net>
PR c++/29573
......
......@@ -1071,9 +1071,15 @@ add_method (tree type, tree method, tree using_decl)
if (insert_p)
{
bool reallocated;
/* We only expect to add few methods in the COMPLETE_P case, so
just make room for one more method in that case. */
if (VEC_reserve (tree, gc, method_vec, complete_p ? -1 : 1))
if (complete_p)
reallocated = VEC_reserve_exact (tree, gc, method_vec, 1);
else
reallocated = VEC_reserve (tree, gc, method_vec, 1);
if (reallocated)
CLASSTYPE_METHOD_VEC (type) = method_vec;
if (slot == VEC_length (tree, method_vec))
VEC_quick_push (tree, method_vec, overload);
......
......@@ -40,16 +40,17 @@ struct vec_prefix
void *vec[1];
};
/* Calculate the new ALLOC value, making sure that abs(RESERVE) slots
are free. If RESERVE < 0 grow exactly, otherwise grow
exponentially. */
/* Calculate the new ALLOC value, making sure that RESERVE slots are
free. If EXACT grow exactly, otherwise grow exponentially. */
static inline unsigned
calculate_allocation (const struct vec_prefix *pfx, int reserve)
calculate_allocation (const struct vec_prefix *pfx, int reserve, bool exact)
{
unsigned alloc = 0;
unsigned num = 0;
gcc_assert (reserve >= 0);
if (pfx)
{
alloc = pfx->alloc;
......@@ -61,11 +62,11 @@ calculate_allocation (const struct vec_prefix *pfx, int reserve)
return 0;
/* We must have run out of room. */
gcc_assert (alloc - num < (unsigned)(reserve < 0 ? -reserve : reserve));
gcc_assert (alloc - num < (unsigned) reserve);
if (reserve < 0)
if (exact)
/* Exact size. */
alloc = num + -reserve;
alloc = num + reserve;
else
{
/* Exponential growth. */
......@@ -85,28 +86,18 @@ calculate_allocation (const struct vec_prefix *pfx, int reserve)
return alloc;
}
/* Ensure there are at least abs(RESERVE) free slots in VEC. If
RESERVE < 0 grow exactly, else grow exponentially. As a special
case, if VEC is NULL, and RESERVE is 0, no vector will be created. */
/* Ensure there are at least RESERVE free slots in VEC. If EXACT grow
exactly, else grow exponentially. As a special case, if VEC is
NULL and RESERVE is 0, no vector will be created. The vector's
trailing array is at VEC_OFFSET offset and consists of ELT_SIZE
sized elements. */
void *
vec_gc_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
return vec_gc_o_reserve (vec, reserve,
offsetof (struct vec_prefix, vec), sizeof (void *)
PASS_MEM_STAT);
}
/* As vec_gc_p_reserve, but for object vectors. The vector's trailing
array is at VEC_OFFSET offset and consists of ELT_SIZE sized
elements. */
void *
vec_gc_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
MEM_STAT_DECL)
static void *
vec_gc_o_reserve_1 (void *vec, int reserve, size_t vec_offset, size_t elt_size,
bool exact MEM_STAT_DECL)
{
struct vec_prefix *pfx = vec;
unsigned alloc = alloc = calculate_allocation (pfx, reserve);
unsigned alloc = alloc = calculate_allocation (pfx, reserve, exact);
if (!alloc)
return NULL;
......@@ -119,24 +110,66 @@ vec_gc_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
return vec;
}
/* As for vec_gc_p_reserve, but for heap allocated vectors. */
/* Ensure there are at least RESERVE free slots in VEC, growing
exponentially. If RESERVE < 0 grow exactly, else grow
exponentially. As a special case, if VEC is NULL, and RESERVE is
0, no vector will be created. */
void *
vec_heap_p_reserve (void *vec, int reserve MEM_STAT_DECL)
vec_gc_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
return vec_heap_o_reserve (vec, reserve,
offsetof (struct vec_prefix, vec), sizeof (void *)
return vec_gc_o_reserve_1 (vec, reserve,
offsetof (struct vec_prefix, vec),
sizeof (void *), false
PASS_MEM_STAT);
}
/* As for vec_gc_o_reserve, but for heap allocated vectors. */
/* Ensure there are at least RESERVE free slots in VEC, growing
exactly. If RESERVE < 0 grow exactly, else grow exponentially. As
a special case, if VEC is NULL, and RESERVE is 0, no vector will be
created. */
void *
vec_heap_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
MEM_STAT_DECL)
vec_gc_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
{
return vec_gc_o_reserve_1 (vec, reserve,
offsetof (struct vec_prefix, vec),
sizeof (void *), true
PASS_MEM_STAT);
}
/* As for vec_gc_p_reserve, but for object vectors. The vector's
trailing array is at VEC_OFFSET offset and consists of ELT_SIZE
sized elements. */
void *
vec_gc_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
MEM_STAT_DECL)
{
return vec_gc_o_reserve_1 (vec, reserve, vec_offset, elt_size, false
PASS_MEM_STAT);
}
/* As for vec_gc_p_reserve_exact, but for object vectors. The
vector's trailing array is at VEC_OFFSET offset and consists of
ELT_SIZE sized elements. */
void *
vec_gc_o_reserve_exact (void *vec, int reserve, size_t vec_offset,
size_t elt_size MEM_STAT_DECL)
{
return vec_gc_o_reserve_1 (vec, reserve, vec_offset, elt_size, true
PASS_MEM_STAT);
}
/* As for vec_gc_o_reserve_1, but for heap allocated vectors. */
static void *
vec_heap_o_reserve_1 (void *vec, int reserve, size_t vec_offset,
size_t elt_size, bool exact MEM_STAT_DECL)
{
struct vec_prefix *pfx = vec;
unsigned alloc = calculate_allocation (pfx, reserve);
unsigned alloc = calculate_allocation (pfx, reserve, exact);
if (!alloc)
return NULL;
......@@ -149,6 +182,48 @@ vec_heap_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
return vec;
}
/* As for vec_gc_p_reserve, but for heap allocated vectors. */
void *
vec_heap_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve,
offsetof (struct vec_prefix, vec),
sizeof (void *), false
PASS_MEM_STAT);
}
/* As for vec_gc_p_reserve_exact, but for heap allocated vectors. */
void *
vec_heap_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve,
offsetof (struct vec_prefix, vec),
sizeof (void *), true
PASS_MEM_STAT);
}
/* As for vec_gc_o_reserve, but for heap allocated vectors. */
void *
vec_heap_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve, vec_offset, elt_size, false
PASS_MEM_STAT);
}
/* As for vec_gc_o_reserve_exact, but for heap allocated vectors. */
void *
vec_heap_o_reserve_exact (void *vec, int reserve, size_t vec_offset,
size_t elt_size MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve, vec_offset, elt_size, true
PASS_MEM_STAT);
}
#if ENABLE_CHECKING
/* Issue a vector domain error, and then fall over. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment