From d5805cc6ebdb9605df46b4a26e263aaee76427c0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 23 Aug 2016 13:05:00 -0400 Subject: [PATCH] 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. --- src/common/intrusive_list.h | 8 ++++++++ src/frontend/ir/basic_block.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/common/intrusive_list.h b/src/common/intrusive_list.h index 021eea05..c7b402e7 100644 --- a/src/common/intrusive_list.h +++ b/src/common/intrusive_list.h @@ -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(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. diff --git a/src/frontend/ir/basic_block.h b/src/frontend/ir/basic_block.h index 2fd6d385..006a2319 100644 --- a/src/frontend/ir/basic_block.h +++ b/src/frontend/ir/basic_block.h @@ -30,6 +30,7 @@ namespace IR { class Block final { public: using InstructionList = Common::IntrusiveList; + 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(); }