aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2004-07-08 09:39:17 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2004-07-08 09:39:17 +0000
commit7de5bcccabe7577efb9e734e5534a2318b1f3703 (patch)
tree2700bf7cb28064eaba654eed36d38552e0016572
parent5df6d966d388fc0c7aae3653f72b37a4c4473646 (diff)
downloadgcc-7de5bcccabe7577efb9e734e5534a2318b1f3703.zip
gcc-7de5bcccabe7577efb9e734e5534a2318b1f3703.tar.gz
gcc-7de5bcccabe7577efb9e734e5534a2318b1f3703.tar.bz2
vec.c (vec_p_reserve, [...]): Allocation is signed.
.: * vec.c (vec_p_reserve, vec_o_reserve): Allocation is signed. * vec.h (VEC_alloc, VEC_embedded_size, VEC_embedded_init): Allocation is signed. (VEC_reserve): Return flag, allocation is signed. cp: * name-lookup.c (push_binding): Use VEC_reserve. From-SVN: r84281
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/name-lookup.c24
-rw-r--r--gcc/vec.c45
-rw-r--r--gcc/vec.h82
5 files changed, 95 insertions, 67 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0b18c51..9baf0be 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2004-07-08 Nathan Sidwell <nathan@codesourcery.com>
+
+ * vec.c (vec_p_reserve, vec_o_reserve): Allocation is signed.
+ * vec.h (VEC_alloc, VEC_embedded_size, VEC_embedded_init):
+ Allocation is signed.
+ (VEC_reserve): Return flag, allocation is signed.
+
2004-07-08 Richard Henderson <rth@redhat.com>
* tree-ssa-ccp.c (fold_stmt): Get type directly from
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d04b5af..8b0bc21 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,7 @@
+2004-07-08 Nathan Sidwell <nathan@codesourcery.com>
+
+ * name-lookup.c (push_binding): Use VEC_reserve.
+
2004-07-08 Richard Henderson <rth@redhat.com>
* cp-tree.h (expand_eh_spec_block): Remove.
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 879d2bf..b070800 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -381,22 +381,22 @@ push_binding (tree id, tree decl, cxx_scope* level)
else
{
cp_class_binding *cb;
- size_t length;
- size_t i;
- bool need_fixup;
- length = VEC_length (cp_class_binding, level->class_shadowed);
- need_fixup = (length && length == level->class_shadowed->alloc);
- cb = VEC_safe_push (cp_class_binding, level->class_shadowed, NULL);
+ if (VEC_reserve (cp_class_binding, level->class_shadowed, -1))
+ {
+ /* Fixup the current bindings, as they might have moved. */
+ size_t i;
+
+ for (i = 0;
+ (cb = VEC_iterate (cp_class_binding, level->class_shadowed, i));
+ i++)
+ IDENTIFIER_BINDING (cb->identifier) = &cb->base;
+ }
+
+ cb = VEC_quick_push (cp_class_binding, level->class_shadowed, NULL);
cb->identifier = id;
binding = &cb->base;
cxx_binding_init (binding, decl, NULL_TREE);
- if (need_fixup)
- for (i = 0; i < length; ++i)
- {
- cb = VEC_index (cp_class_binding, level->class_shadowed, i);
- IDENTIFIER_BINDING (cb->identifier) = &cb->base;
- }
}
/* Now, fill in the binding information. */
diff --git a/gcc/vec.c b/gcc/vec.c
index 01faf52..9d1d8b2 100644
--- a/gcc/vec.c
+++ b/gcc/vec.c
@@ -34,44 +34,45 @@ struct vec_prefix
void *vec[1];
};
-/* Ensure there are at least RESERVE free slots in VEC, if RESERVE !=
- ~0u. If RESERVE == ~0u increase the current allocation
- exponentially. VEC can be NULL, to create a new vector. */
+/* Ensure there are at least RESERVE free slots in VEC, if RESERVE >=
+ 0. If RESERVE < 0 increase the current allocation exponentially.
+ VEC can be NULL, to create a new vector. */
void *
-vec_p_reserve (void *vec, size_t reserve MEM_STAT_DECL)
+vec_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
return vec_o_reserve (vec, reserve,
offsetof (struct vec_prefix, vec), sizeof (void *)
PASS_MEM_STAT);
}
-/* Ensure there are at least RESERVE free slots in VEC, if RESERVE !=
- ~0u. If RESERVE == ~0u, increase the current allocation
- exponentially. VEC can be NULL, in which case a new vector is
- created. The vector's trailing array is at VEC_OFFSET offset and
- consistes of ELT_SIZE sized elements. */
+/* Ensure there are at least RESERVE free slots in VEC, if RESERVE >=
+ 0. If RESERVE < 0, increase the current allocation exponentially.
+ VEC can be NULL, in which case a new vector is created. The
+ vector's trailing array is at VEC_OFFSET offset and consistes of
+ ELT_SIZE sized elements. */
void *
-vec_o_reserve (void *vec, size_t reserve, size_t vec_offset, size_t elt_size
+vec_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
MEM_STAT_DECL)
{
struct vec_prefix *pfx = vec;
- size_t alloc;
+ size_t alloc = pfx ? pfx->num : 0;
- if (reserve + 1)
- alloc = (pfx ? pfx->num : 0) + reserve;
+ if (reserve >= 0)
+ alloc += reserve;
+ else if (alloc)
+ alloc *= 2;
else
- alloc = pfx ? pfx->alloc * 2 : 4;
+ alloc = 4;
+
+ if (pfx && pfx->alloc >= alloc)
+ abort ();
- if (!pfx || pfx->alloc < alloc)
- {
- vec = ggc_realloc_stat (vec, vec_offset + alloc * elt_size
- PASS_MEM_STAT);
- ((struct vec_prefix *)vec)->alloc = alloc;
- if (!pfx)
- ((struct vec_prefix *)vec)->num = 0;
- }
+ vec = ggc_realloc_stat (vec, vec_offset + alloc * elt_size PASS_MEM_STAT);
+ ((struct vec_prefix *)vec)->alloc = alloc;
+ if (!pfx)
+ ((struct vec_prefix *)vec)->num = 0;
return vec;
}
diff --git a/gcc/vec.h b/gcc/vec.h
index be4aaad..84b8dbf 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -58,7 +58,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
vector, if needed. Reallocation causes an exponential increase in
vector size. If you know you will be adding N elements, it would
be more efficient to use the reserve operation before adding the
- elements with the 'quick' operation.
+ elements with the 'quick' operation. You may also use the reserve
+ operation with a -1 operand, to gain control over exactly when
+ reallocation occurs.
You should prefer the push and pop operations, as they append and
remove from the end of the vector. If you need to remove several
@@ -132,27 +134,33 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#define VEC_iterate(TDEF,V,I) (VEC_OP(TDEF,iterate)(V,I))
/* Allocate new vector.
- VEC(T) *VEC_T_alloc(size_t reserve);
+ VEC(T) *VEC_T_alloc(int reserve);
- Allocate a new vector with space for RESERVE objects. */
+ Allocate a new vector with space for RESERVE objects. If RESERVE
+ is <= 0, a default number of slots are created. */
#define VEC_alloc(TDEF,A) (VEC_OP(TDEF,alloc)(A MEM_STAT_INFO))
/* Use these to determine the required size and initialization of a
vector embedded within another structure (as the final member).
- size_t VEC_T_embedded_size(size_t reserve);
- void VEC_T_embedded_init(VEC(T) *v, size_t reserve);
+ size_t VEC_T_embedded_size(int reserve);
+ void VEC_T_embedded_init(VEC(T) *v, int reserve);
These allow the caller to perform the memory allocation. */
#define VEC_embedded_size(TDEF,A) (VEC_OP(TDEF,embedded_size)(A))
#define VEC_embedded_init(TDEF,O,A) (VEC_OP(TDEF,embedded_init)(O,A))
/* Reserve space.
- void VEC_T_reserve(VEC(T) *&v, size_t reserve);
+ int VEC_T_reserve(VEC(T) *&v, int reserve);
- Ensure that V has at least RESERVE slots available. Note this can
- cause V to be reallocated. */
-#define VEC_reserve(TDEF,V,R) (VEC_OP(TDEF,reserve)(&(V),R MEM_STAT_INFO))
+ Ensure that V has at least RESERVE slots available, if RESERVE is
+ >= 0. If RESERVE < 0, ensure that there is at least one spare
+ slot. These differ in their reallocation behaviour, the first will
+ not create additionsl headroom, but the second mechanism will
+ perform the usual exponential headroom increase. Note this can
+ cause V to be reallocated. Returns non-zero iff reallocation
+ actually occurred. */
+#define VEC_reserve(TDEF,V,R) (VEC_OP(TDEF,reserve)(&(V),R MEM_STAT_INFO))
/* Push object with no reallocation
T *VEC_T_quick_push (VEC(T) *v, T obj); // Pointer
@@ -238,8 +246,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#if !IN_GENGTYPE
/* Reallocate an array of elements with prefix. */
-extern void *vec_p_reserve (void *, size_t MEM_STAT_DECL);
-extern void *vec_o_reserve (void *, size_t, size_t, size_t MEM_STAT_DECL);
+extern void *vec_p_reserve (void *, int MEM_STAT_DECL);
+extern void *vec_o_reserve (void *, int, size_t, size_t MEM_STAT_DECL);
#if ENABLE_CHECKING
extern void vec_assert_fail (const char *, const char *,
@@ -310,28 +318,34 @@ static inline TDEF VEC_OP (TDEF,iterate) \
} \
\
static inline VEC (TDEF) *VEC_OP (TDEF,alloc MEM_STAT_DECL) \
- (size_t alloc_) \
+ (int alloc_) \
{ \
return vec_p_reserve (NULL, alloc_ - !alloc_ PASS_MEM_STAT); \
} \
\
static inline size_t VEC_OP (TDEF,embedded_size) \
- (size_t alloc_) \
+ (int alloc_) \
{ \
return offsetof (VEC(TDEF),vec) + alloc_ * sizeof(TDEF); \
} \
\
static inline void VEC_OP (TDEF,embedded_init) \
- (VEC (TDEF) *vec_, size_t alloc_) \
+ (VEC (TDEF) *vec_, int alloc_) \
{ \
vec_->num = 0; \
vec_->alloc = alloc_; \
} \
\
-static inline void VEC_OP (TDEF,reserve) \
- (VEC (TDEF) **vec_, size_t alloc_ MEM_STAT_DECL) \
+static inline int VEC_OP (TDEF,reserve) \
+ (VEC (TDEF) **vec_, int alloc_ MEM_STAT_DECL) \
{ \
- *vec_ = vec_p_reserve (*vec_, alloc_ PASS_MEM_STAT); \
+ int extend = !*vec_ || ((*vec_)->alloc - (*vec_)->num \
+ < (size_t)(alloc_ < 0 ? 1 : alloc_)); \
+ \
+ if (extend) \
+ *vec_ = vec_p_reserve (*vec_, alloc_ PASS_MEM_STAT); \
+ \
+ return extend; \
} \
\
static inline TDEF *VEC_OP (TDEF,quick_push) \
@@ -349,8 +363,7 @@ static inline TDEF *VEC_OP (TDEF,quick_push) \
static inline TDEF *VEC_OP (TDEF,safe_push) \
(VEC (TDEF) **vec_, TDEF obj_ MEM_STAT_DECL) \
{ \
- if (!*vec_ || (*vec_)->num == (*vec_)->alloc) \
- VEC_OP (TDEF,reserve) (vec_, ~(size_t)0 PASS_MEM_STAT); \
+ VEC_OP (TDEF,reserve) (vec_, -1 PASS_MEM_STAT); \
\
return VEC_OP (TDEF,quick_push) (*vec_, obj_); \
} \
@@ -402,8 +415,7 @@ static inline TDEF *VEC_OP (TDEF,quick_insert) \
static inline TDEF *VEC_OP (TDEF,safe_insert) \
(VEC (TDEF) **vec_, size_t ix_, TDEF obj_ MEM_STAT_DECL) \
{ \
- if (!*vec_ || (*vec_)->num == (*vec_)->alloc) \
- VEC_OP (TDEF,reserve) (vec_, ~(size_t)0 PASS_MEM_STAT); \
+ VEC_OP (TDEF,reserve) (vec_, -1 PASS_MEM_STAT); \
\
return VEC_OP (TDEF,quick_insert) (*vec_, ix_, obj_); \
} \
@@ -476,7 +488,7 @@ static inline TDEF *VEC_OP (TDEF,iterate) \
} \
\
static inline VEC (TDEF) *VEC_OP (TDEF,alloc) \
- (size_t alloc_ MEM_STAT_DECL) \
+ (int alloc_ MEM_STAT_DECL) \
{ \
return vec_o_reserve (NULL, alloc_ - !alloc_, \
offsetof (VEC(TDEF),vec), sizeof (TDEF) \
@@ -484,24 +496,30 @@ static inline VEC (TDEF) *VEC_OP (TDEF,alloc) \
} \
\
static inline size_t VEC_OP (TDEF,embedded_size) \
- (size_t alloc_) \
+ (int alloc_) \
{ \
return offsetof (VEC(TDEF),vec) + alloc_ * sizeof(TDEF); \
} \
\
static inline void VEC_OP (TDEF,embedded_init) \
- (VEC (TDEF) *vec_, size_t alloc_) \
+ (VEC (TDEF) *vec_, int alloc_) \
{ \
vec_->num = 0; \
vec_->alloc = alloc_; \
} \
\
-static inline void VEC_OP (TDEF,reserve) \
- (VEC (TDEF) **vec_, size_t alloc_ MEM_STAT_DECL) \
+static inline int VEC_OP (TDEF,reserve) \
+ (VEC (TDEF) **vec_, int alloc_ MEM_STAT_DECL) \
{ \
- *vec_ = vec_o_reserve (*vec_, alloc_, \
- offsetof (VEC(TDEF),vec), sizeof (TDEF) \
- PASS_MEM_STAT); \
+ int extend = !*vec_ || ((*vec_)->alloc - (*vec_)->num \
+ < (size_t)(alloc_ < 0 ? 1 : alloc_)); \
+ \
+ if (extend) \
+ *vec_ = vec_o_reserve (*vec_, alloc_, \
+ offsetof (VEC(TDEF),vec), sizeof (TDEF) \
+ PASS_MEM_STAT); \
+ \
+ return extend; \
} \
\
static inline TDEF *VEC_OP (TDEF,quick_push) \
@@ -520,8 +538,7 @@ static inline TDEF *VEC_OP (TDEF,quick_push) \
static inline TDEF *VEC_OP (TDEF,safe_push) \
(VEC (TDEF) **vec_, const TDEF *obj_ MEM_STAT_DECL) \
{ \
- if (!*vec_ || (*vec_)->num == (*vec_)->alloc) \
- VEC_OP (TDEF,reserve) (vec_, ~(size_t)0 PASS_MEM_STAT); \
+ VEC_OP (TDEF,reserve) (vec_, -1 PASS_MEM_STAT); \
\
return VEC_OP (TDEF,quick_push) (*vec_, obj_); \
} \
@@ -571,8 +588,7 @@ static inline TDEF *VEC_OP (TDEF,quick_insert) \
static inline TDEF *VEC_OP (TDEF,safe_insert) \
(VEC (TDEF) **vec_, size_t ix_, const TDEF *obj_ MEM_STAT_DECL) \
{ \
- if (!*vec_ || (*vec_)->num == (*vec_)->alloc) \
- VEC_OP (TDEF,reserve) (vec_, ~(size_t)0 PASS_MEM_STAT); \
+ VEC_OP (TDEF,reserve) (vec_, -1 PASS_MEM_STAT); \
\
return VEC_OP (TDEF,quick_insert) (*vec_, ix_, obj_); \
} \