diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2018-03-06 09:51:33 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2018-03-06 09:51:33 -0500 |
commit | 531270084129e069772e68ead40c97404d1c0dd7 (patch) | |
tree | 44b59e96a22b317d794d623dcfe1e62035a19352 /gdb/common | |
parent | 228f15081e22abed7ea336126caba26de5a3b791 (diff) | |
download | gdb-531270084129e069772e68ead40c97404d1c0dd7.zip gdb-531270084129e069772e68ead40c97404d1c0dd7.tar.gz gdb-531270084129e069772e68ead40c97404d1c0dd7.tar.bz2 |
btrace: Remove VEC cleanups
This patch replaces two VEC(tp_t) with std::vector<thread_info *>, 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<thread_info *>.
* common/gdb_vecs.h (unordered_remove, ordered_remove): New.
Diffstat (limited to 'gdb/common')
-rw-r--r-- | gdb/common/gdb_vecs.h | 31 |
1 files changed, 31 insertions, 0 deletions
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<gdb::unique_xmalloc_ptr<char>> 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 <typename T> +T +unordered_remove (std::vector<T> &vec, typename std::vector<T>::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 <typename T> +T +ordered_remove (std::vector<T> &vec, typename std::vector<T>::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 */ |