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:
Lioncash 2016-08-23 13:05:00 -04:00 committed by MerryMage
parent 2180a4be7a
commit d5805cc6eb
2 changed files with 10 additions and 0 deletions

View file

@ -216,6 +216,14 @@ public:
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.
* @note Must not be called on an empty list.

View file

@ -30,6 +30,7 @@ namespace IR {
class Block final {
public:
using InstructionList = Common::IntrusiveList<Inst>;
using size_type = InstructionList::size_type;
using iterator = InstructionList::iterator;
using const_iterator = InstructionList::const_iterator;
using reverse_iterator = InstructionList::reverse_iterator;
@ -38,6 +39,7 @@ public:
explicit Block(const Arm::LocationDescriptor& location) : location(location) {}
bool empty() const { return instructions.empty(); }
size_type size() const { return instructions.size(); }
Inst& front() { return instructions.front(); }
const Inst& front() const { return instructions.front(); }