File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,16 +47,10 @@ template <typename T> class ImmutableList {
4747
4848 struct iterator {
4949 const ImmutableListNode *rootNode;
50- std::unique_ptr<iterator> it;
5150 size_t get;
5251
5352 public:
54- explicit iterator (const ImmutableListNode *p)
55- : rootNode(p), it(nullptr ), get(0 ) {
56- if (rootNode && rootNode->prev .get ()) {
57- it = std::make_unique<iterator>(rootNode->prev .get ());
58- }
59- }
53+ explicit iterator (const ImmutableListNode *p) : rootNode(p), get(0 ) {}
6054
6155 bool operator ==(const iterator &b) const {
6256 return rootNode == b.rootNode && get == b.get ;
@@ -66,17 +60,16 @@ template <typename T> class ImmutableList {
6660
6761 iterator &operator ++() {
6862 ++get;
69- if (get < rootNode->prev_len ) {
70- it->operator ++();
71- }
7263 return *this ;
7364 }
7465
7566 const T &operator *() const {
76- if (get < rootNode->prev_len ) {
77- return **it;
67+ assert (get < rootNode->size () && " Out of bound" );
68+ const ImmutableListNode *curNode = rootNode;
69+ while (get < curNode->prev_len ) {
70+ curNode = curNode->prev .get ();
7871 }
79- return rootNode ->values [get - rootNode ->prev_len ];
72+ return curNode ->values [get - curNode ->prev_len ];
8073 }
8174
8275 const T &operator ->() const { return **this ; }
You can’t perform that action at this time.
0 commit comments