From 531270084129e069772e68ead40c97404d1c0dd7 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 6 Mar 2018 09:51:33 -0500 Subject: btrace: Remove VEC cleanups This patch replaces two VEC(tp_t) with std::vector, which allows to remove two cleanups. To make it easier to map the old code to the new code, I added the ordered_remove and unordered_remove functions, which operate on std::vector and do the same as VEC's ordered_remove/unordered_remove. gdb/ChangeLog: * record-btrace.c (record_btrace_maybe_mark_async_event): Change parameter types to std::vector. Use bool. (record_btrace_wait): Replace VEC(tp_t) with std::vector. * common/gdb_vecs.h (unordered_remove, ordered_remove): New. --- gdb/common/gdb_vecs.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'gdb/common') diff --git a/gdb/common/gdb_vecs.h b/gdb/common/gdb_vecs.h index 29db27a..7318e53 100644 --- a/gdb/common/gdb_vecs.h +++ b/gdb/common/gdb_vecs.h @@ -50,4 +50,35 @@ extern void dirnames_to_char_ptr_vec_append extern std::vector> dirnames_to_char_ptr_vec (const char *dirnames); +/* Remove the element at position IX from VEC, not preserving the order of the + remaining elements. Return the removed element. */ + +template +T +unordered_remove (std::vector &vec, typename std::vector::size_type ix) +{ + gdb_assert (ix < vec.size ()); + + T removed = std::move (vec[ix]); + vec[ix] = std::move (vec.back ()); + vec.pop_back (); + + return removed; +} + +/* Remove the element at position IX from VEC, preserving the order the + remaining elements. Return the removed element. */ + +template +T +ordered_remove (std::vector &vec, typename std::vector::size_type ix) +{ + gdb_assert (ix < vec.size ()); + + T removed = std::move (vec[ix]); + vec.erase (vec.begin () + ix); + + return removed; +} + #endif /* GDB_VECS_H */ -- cgit v1.1