aboutsummaryrefslogtreecommitdiff
path: root/gcc/vec.h
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2012-09-10 20:04:13 -0400
committerDiego Novillo <dnovillo@gcc.gnu.org>2012-09-10 20:04:13 -0400
commitf32682ca2516e009432be7f0dc0e4e4bfab9a944 (patch)
tree3030f0ec079f1a93f960208e432eb6f275d10a28 /gcc/vec.h
parentda4c5b2465322894e6d53cd14128ba21d0ff911b (diff)
downloadgcc-f32682ca2516e009432be7f0dc0e4e4bfab9a944.zip
gcc-f32682ca2516e009432be7f0dc0e4e4bfab9a944.tar.gz
gcc-f32682ca2516e009432be7f0dc0e4e4bfab9a944.tar.bz2
Remove unnecessary VEC function overloads.
Several VEC member functions that accept an element 'T' used to have two overloads: one taking 'T', the second taking 'T *'. This used to be needed because of the interface dichotomy between vectors of objects and vectors of pointers. In the past, vectors of pointers would use pass-by-value semantics, but vectors of objects would use pass-by-reference semantics. This is no longer necessary, but the distinction had remained. The main side-effect of this change is some code reduction in code that manipulates vectors of objects. For instance, - struct iterator_use *iuse; - - iuse = VEC_safe_push (iterator_use, heap, iterator_uses, NULL); - iuse->iterator = iterator; - iuse->ptr = ptr; + struct iterator_use iuse = {iterator, ptr}; + VEC_safe_push (iterator_use, heap, iterator_uses, iuse); Compile time performance was not affected. Tested on x86_64 and ppc64. Also built all-gcc on all targets using VEC routines: arm, bfin, c6x, epiphany, ia64, mips, sh, spu, and vms. 2012-09-10 Diego Novillo <dnovillo@google.com> * vec.h (vec_t::quick_push): Remove overload that accepts 'T *'. Update all users. (vec_t::safe_push): Likewise. (vec_t::quick_insert): Likewise. (vec_t::lower_bound): Likewise. (vec_t::safe_insert): Likewise. (vec_t::replace): Change second argument to 'T &'. From-SVN: r191165
Diffstat (limited to 'gcc/vec.h')
-rw-r--r--gcc/vec.h149
1 files changed, 21 insertions, 128 deletions
diff --git a/gcc/vec.h b/gcc/vec.h
index fbf95d2..88891d7 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -178,19 +178,15 @@ struct GTY(()) vec_t
bool space (int VEC_CHECK_DECL);
void splice (vec_t<T> * VEC_CHECK_DECL);
- T &quick_push (T VEC_CHECK_DECL);
- T *quick_push (const T * VEC_CHECK_DECL);
+ T *quick_push (const T & VEC_CHECK_DECL);
T &pop (ALONE_VEC_CHECK_DECL);
void truncate (unsigned VEC_CHECK_DECL);
- void replace (unsigned, T VEC_CHECK_DECL);
- void quick_insert (unsigned, T VEC_CHECK_DECL);
- void quick_insert (unsigned, const T * VEC_CHECK_DECL);
+ void replace (unsigned, const T & VEC_CHECK_DECL);
+ void quick_insert (unsigned, const T & VEC_CHECK_DECL);
void ordered_remove (unsigned VEC_CHECK_DECL);
void unordered_remove (unsigned VEC_CHECK_DECL);
void block_remove (unsigned, unsigned VEC_CHECK_DECL);
-
- unsigned lower_bound (T, bool (*)(T, T)) const;
- unsigned lower_bound (const T *, bool (*)(const T *, const T *)) const;
+ unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
/* Class-static member functions. Some of these will become member
functions of a future handler class wrapping vec_t. */
@@ -221,10 +217,7 @@ struct GTY(()) vec_t
MEM_STAT_DECL);
template<enum vec_allocation_t A>
- static T &safe_push (vec_t<T> **, T VEC_CHECK_DECL MEM_STAT_DECL);
-
- template<enum vec_allocation_t A>
- static T *safe_push (vec_t<T> **, const T * VEC_CHECK_DECL MEM_STAT_DECL);
+ static T *safe_push (vec_t<T> **, const T & VEC_CHECK_DECL MEM_STAT_DECL);
template<enum vec_allocation_t A>
static void safe_grow (vec_t<T> **, int VEC_CHECK_DECL MEM_STAT_DECL);
@@ -233,11 +226,7 @@ struct GTY(()) vec_t
static void safe_grow_cleared (vec_t<T> **, int VEC_CHECK_DECL MEM_STAT_DECL);
template<enum vec_allocation_t A>
- static void safe_insert (vec_t<T> **, unsigned, T * VEC_CHECK_DECL
- MEM_STAT_DECL);
-
- template<enum vec_allocation_t A>
- static void safe_insert (vec_t<T> **, unsigned, T obj VEC_CHECK_DECL
+ static void safe_insert (vec_t<T> **, unsigned, const T & VEC_CHECK_DECL
MEM_STAT_DECL);
static bool iterate (const vec_t<T> *, unsigned, T *);
@@ -802,63 +791,32 @@ vec_t<T>::safe_splice (vec_t<T> **dst, vec_t<T> *src VEC_CHECK_DECL
}
-/* Push OBJ (a new element) onto the end, returns a reference to the slot
- filled in. There must be sufficient space in the vector. */
-
-template<typename T>
-T &
-vec_t<T>::quick_push (T obj VEC_CHECK_DECL)
-{
- VEC_ASSERT (prefix_.num_ < prefix_.alloc_, "push", T, base);
- vec_[prefix_.num_] = obj;
- T &val = vec_[prefix_.num_];
- prefix_.num_++;
- return val;
-}
+/* Push OBJ (a new element) onto the end of the vector. There must be
+ sufficient space in the vector. Return a pointer to the slot
+ where OBJ was inserted. */
-/* Push PTR (a new pointer to an element) onto the end, returns a
- pointer to the slot filled in. The new value can be NULL, in which
- case NO initialization is performed. There must be sufficient
- space in the vector. */
-
template<typename T>
T *
-vec_t<T>::quick_push (const T *ptr VEC_CHECK_DECL)
+vec_t<T>::quick_push (const T &obj VEC_CHECK_DECL)
{
VEC_ASSERT (prefix_.num_ < prefix_.alloc_, "push", T, base);
T *slot = &vec_[prefix_.num_++];
- if (ptr)
- *slot = *ptr;
+ *slot = obj;
return slot;
}
-/* Push a new element OBJ onto the end of VEC. Returns a reference to
- the slot filled in. Reallocates V, if needed. */
-
-template<typename T>
-template<enum vec_allocation_t A>
-T &
-vec_t<T>::safe_push (vec_t<T> **vec, T obj VEC_CHECK_DECL MEM_STAT_DECL)
-{
- reserve<A> (vec, 1 VEC_CHECK_PASS PASS_MEM_STAT);
- return (*vec)->quick_push (obj VEC_CHECK_PASS);
-}
-
-
-/* Push a pointer PTR to a new element onto the end of VEC. Returns a
- pointer to the slot filled in. For object vectors, the new value
- can be NULL, in which case NO initialization is performed.
- Reallocates VEC, if needed. */
+/* Push a new element OBJ onto the end of VEC. Reallocates VEC, if
+ needed. Return a pointer to the slot where OBJ was inserted. */
template<typename T>
template<enum vec_allocation_t A>
T *
-vec_t<T>::safe_push (vec_t<T> **vec, const T *ptr VEC_CHECK_DECL MEM_STAT_DECL)
+vec_t<T>::safe_push (vec_t<T> **vec, const T &obj VEC_CHECK_DECL MEM_STAT_DECL)
{
reserve<A> (vec, 1 VEC_CHECK_PASS PASS_MEM_STAT);
- return (*vec)->quick_push (ptr VEC_CHECK_PASS);
+ return (*vec)->quick_push (obj VEC_CHECK_PASS);
}
@@ -923,7 +881,7 @@ vec_t<T>::safe_grow_cleared (vec_t<T> **vec, int size VEC_CHECK_DECL
template<typename T>
void
-vec_t<T>::replace (unsigned ix, T obj VEC_CHECK_DECL)
+vec_t<T>::replace (unsigned ix, const T &obj VEC_CHECK_DECL)
{
VEC_ASSERT (ix < prefix_.num_, "replace", T, base);
vec_[ix] = obj;
@@ -935,7 +893,7 @@ vec_t<T>::replace (unsigned ix, T obj VEC_CHECK_DECL)
template<typename T>
void
-vec_t<T>::quick_insert (unsigned ix, T obj VEC_CHECK_DECL)
+vec_t<T>::quick_insert (unsigned ix, const T &obj VEC_CHECK_DECL)
{
VEC_ASSERT (prefix_.num_ < prefix_.alloc_, "insert", T, base);
VEC_ASSERT (ix <= prefix_.num_, "insert", T, base);
@@ -945,30 +903,13 @@ vec_t<T>::quick_insert (unsigned ix, T obj VEC_CHECK_DECL)
}
-/* Insert an element, *PTR, at the IXth position of V. The new value
- can be NULL, in which case no initialization of the inserted slot
- takes place. There must be sufficient space. */
-
-template<typename T>
-void
-vec_t<T>::quick_insert (unsigned ix, const T *ptr VEC_CHECK_DECL)
-{
- VEC_ASSERT (prefix_.num_ < prefix_.alloc_, "insert", T, base);
- VEC_ASSERT (ix <= prefix_.num_, "insert", T, base);
- T *slot = &vec_[ix];
- memmove (slot + 1, slot, (prefix_.num_++ - ix) * sizeof (T));
- if (ptr)
- *slot = *ptr;
-}
-
-
-/* Insert an element, VAL, at the IXth position of VEC. Reallocate
+/* Insert an element, OBJ, at the IXth position of VEC. Reallocate
VEC, if necessary. */
template<typename T>
template<enum vec_allocation_t A>
void
-vec_t<T>::safe_insert (vec_t<T> **vec, unsigned ix, T obj VEC_CHECK_DECL
+vec_t<T>::safe_insert (vec_t<T> **vec, unsigned ix, const T &obj VEC_CHECK_DECL
MEM_STAT_DECL)
{
reserve<A> (vec, 1 VEC_CHECK_PASS PASS_MEM_STAT);
@@ -976,22 +917,6 @@ vec_t<T>::safe_insert (vec_t<T> **vec, unsigned ix, T obj VEC_CHECK_DECL
}
-/* Insert an element, *PTR, at the IXth position of VEC. Return a pointer
- to the slot created. For vectors of object, the new value can be
- NULL, in which case no initialization of the inserted slot takes
- place. Reallocate V, if necessary. */
-
-template<typename T>
-template<enum vec_allocation_t A>
-void
-vec_t<T>::safe_insert (vec_t<T> **vec, unsigned ix, T *ptr VEC_CHECK_DECL
- MEM_STAT_DECL)
-{
- reserve<A> (vec, 1 VEC_CHECK_PASS PASS_MEM_STAT);
- (*vec)->quick_insert (ix, ptr VEC_CHECK_PASS);
-}
-
-
/* Remove an element from the IXth position of this vector. Ordering of
remaining elements is preserved. This is an O(N) operation due to
a memmove. */
@@ -1043,14 +968,14 @@ vec_t<T>::block_remove (unsigned ix, unsigned len VEC_CHECK_DECL)
template<typename T>
unsigned
-vec_t<T>::lower_bound (T obj, bool (*lessthan)(T, T)) const
+vec_t<T>::lower_bound (T obj, bool (*lessthan)(const T &, const T &)) const
{
unsigned int len = VEC_length (T, this);
unsigned int half, middle;
unsigned int first = 0;
while (len > 0)
{
- half = len >> 1;
+ half = len / 2;
middle = first;
middle += half;
T middle_elem = (*this)[middle];
@@ -1067,38 +992,6 @@ vec_t<T>::lower_bound (T obj, bool (*lessthan)(T, T)) const
}
-/* Find and return the first position in which *PTR could be inserted
- without changing the ordering of this vector. LESSTHAN is a
- function that returns true if the first argument is strictly less
- than the second. */
-
-template<typename T>
-unsigned
-vec_t<T>::lower_bound (const T *ptr,
- bool (*lessthan)(const T *, const T *)) const
-{
- unsigned int len = VEC_length (T, this);
- unsigned int half, middle;
- unsigned int first = 0;
- while (len > 0)
- {
- half = len >> 1;
- middle = first;
- middle += half;
- const T *middle_elem = &(*this)[middle];
- if (lessthan (middle_elem, ptr))
- {
- first = middle;
- ++first;
- len = len - half - 1;
- }
- else
- len = half;
- }
- return first;
-}
-
-
void *vec_heap_o_reserve_1 (void *, int, size_t, size_t, bool MEM_STAT_DECL);
void *vec_gc_o_reserve_1 (void *, int, size_t, size_t, bool MEM_STAT_DECL);