forked from Imagelibrary/binutils-gdb
Add move operators for addrmap
A subsequent patch needs to move an addrmap. This patch adds the necessary support. It also changes addrmap_fixed to take a 'const' addrmap_mutable. This is fine according to the contract of addrmap_mutable; but it did require a compensating const_cast in the implementation.
This commit is contained in:
@@ -250,12 +250,13 @@ addrmap_mutable::do_find (CORE_ADDR addr) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
addrmap_fixed::addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut)
|
addrmap_fixed::addrmap_fixed (struct obstack *obstack,
|
||||||
|
const addrmap_mutable *mut)
|
||||||
{
|
{
|
||||||
size_t transition_count = 0;
|
size_t transition_count = 0;
|
||||||
|
|
||||||
/* Count the number of transitions in the tree. */
|
/* Count the number of transitions in the tree. */
|
||||||
mut->foreach ([&] (CORE_ADDR start, void *obj)
|
mut->foreach ([&] (CORE_ADDR start, const void *obj)
|
||||||
{
|
{
|
||||||
++transition_count;
|
++transition_count;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -273,10 +274,10 @@ addrmap_fixed::addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut)
|
|||||||
|
|
||||||
/* Copy all entries from the splay tree to the array, in order
|
/* Copy all entries from the splay tree to the array, in order
|
||||||
of increasing address. */
|
of increasing address. */
|
||||||
mut->foreach ([&] (CORE_ADDR start, void *obj)
|
mut->foreach ([&] (CORE_ADDR start, const void *obj)
|
||||||
{
|
{
|
||||||
transitions[num_transitions].addr = start;
|
transitions[num_transitions].addr = start;
|
||||||
transitions[num_transitions].value = obj;
|
transitions[num_transitions].value = const_cast<void *> (obj);
|
||||||
++num_transitions;
|
++num_transitions;
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
@@ -344,6 +345,7 @@ addrmap_mutable::addrmap_mutable ()
|
|||||||
|
|
||||||
addrmap_mutable::~addrmap_mutable ()
|
addrmap_mutable::~addrmap_mutable ()
|
||||||
{
|
{
|
||||||
|
if (tree != nullptr)
|
||||||
splay_tree_delete (tree);
|
splay_tree_delete (tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,9 +85,14 @@ struct addrmap_fixed final : public addrmap,
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut);
|
addrmap_fixed (struct obstack *obstack, const addrmap_mutable *mut);
|
||||||
DISABLE_COPY_AND_ASSIGN (addrmap_fixed);
|
DISABLE_COPY_AND_ASSIGN (addrmap_fixed);
|
||||||
|
|
||||||
|
/* It's fine to use the default move operators, because this addrmap
|
||||||
|
does not own the storage for the elements. */
|
||||||
|
addrmap_fixed (addrmap_fixed &&other) = default;
|
||||||
|
addrmap_fixed &operator= (addrmap_fixed &&) = default;
|
||||||
|
|
||||||
void relocate (CORE_ADDR offset) override;
|
void relocate (CORE_ADDR offset) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -124,6 +129,18 @@ public:
|
|||||||
~addrmap_mutable ();
|
~addrmap_mutable ();
|
||||||
DISABLE_COPY_AND_ASSIGN (addrmap_mutable);
|
DISABLE_COPY_AND_ASSIGN (addrmap_mutable);
|
||||||
|
|
||||||
|
addrmap_mutable (addrmap_mutable &&other)
|
||||||
|
: tree (other.tree)
|
||||||
|
{
|
||||||
|
other.tree = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
addrmap_mutable &operator= (addrmap_mutable &&other)
|
||||||
|
{
|
||||||
|
std::swap (tree, other.tree);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
/* In the mutable address map MAP, associate the addresses from START
|
/* In the mutable address map MAP, associate the addresses from START
|
||||||
to END_INCLUSIVE that are currently associated with NULL with OBJ
|
to END_INCLUSIVE that are currently associated with NULL with OBJ
|
||||||
instead. Addresses mapped to an object other than NULL are left
|
instead. Addresses mapped to an object other than NULL are left
|
||||||
|
|||||||
Reference in New Issue
Block a user