diff --git a/js/src/jit/InlineList.h b/js/src/jit/InlineList.h index 441fdfed8716..2f849644143c 100644 --- a/js/src/jit/InlineList.h +++ b/js/src/jit/InlineList.h @@ -390,6 +390,92 @@ class InlineListReverseIterator Node *iter; }; +/* This list type is more or less exactly an InlineForwardList without a sentinel + * node. It is useful in cases where you are doing algorithms that deal with many + * merging singleton lists, rather than often empty ones. + */ +template class InlineConcatListIterator; +template +class InlineConcatList +{ + private: + typedef InlineConcatList Node; + + InlineConcatList *thisFromConstructor() { + return this; + } + + public: + InlineConcatList() : next(NULL), tail(thisFromConstructor()) + { } + + typedef InlineConcatListIterator iterator; + + iterator begin() const { + return iterator(this); + } + + iterator end() const { + return iterator(NULL); + } + + void append(InlineConcatList *adding) + { + JS_ASSERT(tail); + JS_ASSERT(!tail->next); + JS_ASSERT(adding->tail); + JS_ASSERT(!adding->tail->next); + + tail->next = adding; + tail = adding->tail; + adding->tail = NULL; + } + + protected: + friend class InlineConcatListIterator; + Node *next; + Node *tail; +}; + +template +class InlineConcatListIterator +{ + private: + friend class InlineConcatList; + + typedef InlineConcatList Node; + + InlineConcatListIterator(const Node *iter) + : iter(const_cast(iter)) + { } + + public: + InlineConcatListIterator & operator ++() { + iter = iter->next; + return *iter; + } + InlineConcatListIterator operator ++(int) { + InlineConcatListIterator old(*this); + iter = static_cast(iter->next); + return old; + } + T * operator *() const { + return static_cast(iter); + } + T * operator ->() const { + return static_cast(iter); + } + bool operator !=(const InlineConcatListIterator &where) const { + return iter != where.iter; + } + bool operator ==(const InlineConcatListIterator &where) const { + return iter == where.iter; + } + + private: + Node *iter; +}; + } // namespace js #endif /* jit_InlineList_h */