intrusive_list: Add size querying
Since we store pointers and have an interface for iterators set up, the count is just the distance from the beginning to the end of the list. Nice thing is that because of this, basic blocks also get the ability to have a size count without needing to do anything directly.
This commit is contained in:
parent
2180a4be7a
commit
d5805cc6eb
2 changed files with 10 additions and 0 deletions
|
@ -216,6 +216,14 @@ public:
|
||||||
return root->next == root.get();
|
return root->next == root.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total number of elements within this list.
|
||||||
|
* @return the number of elements in this list.
|
||||||
|
*/
|
||||||
|
size_type size() const {
|
||||||
|
return static_cast<size_type>(std::distance(begin(), end()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a reference to the node at the front of the list.
|
* Retrieves a reference to the node at the front of the list.
|
||||||
* @note Must not be called on an empty list.
|
* @note Must not be called on an empty list.
|
||||||
|
|
|
@ -30,6 +30,7 @@ namespace IR {
|
||||||
class Block final {
|
class Block final {
|
||||||
public:
|
public:
|
||||||
using InstructionList = Common::IntrusiveList<Inst>;
|
using InstructionList = Common::IntrusiveList<Inst>;
|
||||||
|
using size_type = InstructionList::size_type;
|
||||||
using iterator = InstructionList::iterator;
|
using iterator = InstructionList::iterator;
|
||||||
using const_iterator = InstructionList::const_iterator;
|
using const_iterator = InstructionList::const_iterator;
|
||||||
using reverse_iterator = InstructionList::reverse_iterator;
|
using reverse_iterator = InstructionList::reverse_iterator;
|
||||||
|
@ -38,6 +39,7 @@ public:
|
||||||
explicit Block(const Arm::LocationDescriptor& location) : location(location) {}
|
explicit Block(const Arm::LocationDescriptor& location) : location(location) {}
|
||||||
|
|
||||||
bool empty() const { return instructions.empty(); }
|
bool empty() const { return instructions.empty(); }
|
||||||
|
size_type size() const { return instructions.size(); }
|
||||||
|
|
||||||
Inst& front() { return instructions.front(); }
|
Inst& front() { return instructions.front(); }
|
||||||
const Inst& front() const { return instructions.front(); }
|
const Inst& front() const { return instructions.front(); }
|
||||||
|
|
Loading…
Reference in a new issue