Changeset 96733 in webkit for trunk/Source/JavaScriptCore/wtf


Ignore:
Timestamp:
Oct 5, 2011, 11:29:58 AM (14 years ago)
Author:
[email protected]
Message:

Use std::reverse_iterator for ListHashSet reverse iterators
https://bugs.webkit.org/show_bug.cgi?id=69446

Reviewed by Darin Adler.

  • wtf/ListHashSet.h:

Use the std::reverse_iterator iterator adaptor for the ListHashSet reverse iterators
and get rid of the ListHashSetReverseIterator and ListHashSetConstReverseIterator classes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wtf/ListHashSet.h

    r96648 r96733  
    2828#include "PassOwnPtr.h"
    2929#include "StdLibExtras.h"
     30#include <iterator>
    3031
    3132namespace WTF {
     
    5051    template<typename ValueArg, size_t inlineCapacity, typename HashArg> class ListHashSetIterator;
    5152    template<typename ValueArg, size_t inlineCapacity, typename HashArg> class ListHashSetConstIterator;
    52     template<typename ValueArg, size_t inlineCapacity, typename HashArg> class ListHashSetReverseIterator;
    53     template<typename ValueArg, size_t inlineCapacity, typename HashArg> class ListHashSetConstReverseIterator;
    5453
    5554    template<typename ValueArg, size_t inlineCapacity> struct ListHashSetNode;
     
    7978        friend class ListHashSetConstIterator<ValueType, inlineCapacity, HashArg>;
    8079
    81         typedef ListHashSetReverseIterator<ValueType, inlineCapacity, HashArg> reverse_iterator;
    82         typedef ListHashSetConstReverseIterator<ValueType, inlineCapacity, HashArg> const_reverse_iterator;
    83         friend class ListHashSetConstReverseIterator<ValueType, inlineCapacity, HashArg>;
     80        typedef std::reverse_iterator<iterator> reverse_iterator;
     81        typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
    8482
    8583        ListHashSet();
     
    141139        iterator makeIterator(Node*);
    142140        const_iterator makeConstIterator(Node*) const;
    143         reverse_iterator makeReverseIterator(Node*);
    144         const_reverse_iterator makeConstReverseIterator(Node*) const;
    145141
    146142        friend void deleteAllValues<>(const ListHashSet&);
     
    272268
    273269        friend class ListHashSet<ValueArg, inlineCapacity, HashArg>;
    274 
     270       
    275271        ListHashSetIterator(const ListHashSetType* set, Node* position) : m_iterator(set, position) { }
    276272
    277273    public:
     274        typedef std::bidirectional_iterator_tag iterator_category;
     275        typedef ValueType value_type;
     276        typedef ReferenceType reference;
     277        typedef PointerType pointer;
     278        typedef int difference_type;
     279
    278280        ListHashSetIterator() { }
    279281
     
    324326
    325327    public:
     328        typedef std::bidirectional_iterator_tag iterator_category;
     329        typedef ValueType value_type;
     330        typedef ReferenceType reference;
     331        typedef PointerType pointer;
     332        typedef int difference_type;
     333
    326334        ListHashSetConstIterator()
    327335        {
     
    373381    };
    374382
    375     template<typename ValueArg, size_t inlineCapacity, typename HashArg> class ListHashSetReverseIterator {
    376     private:
    377         typedef ListHashSet<ValueArg, inlineCapacity, HashArg> ListHashSetType;
    378         typedef ListHashSetReverseIterator<ValueArg, inlineCapacity, HashArg> reverse_iterator;
    379         typedef ListHashSetConstIterator<ValueArg, inlineCapacity, HashArg> const_reverse_iterator;
    380         typedef ListHashSetNode<ValueArg, inlineCapacity> Node;
    381         typedef ValueArg ValueType;
    382         typedef ValueType& ReferenceType;
    383         typedef ValueType* PointerType;
    384 
    385         friend class ListHashSet<ValueArg, inlineCapacity, HashArg>;
    386 
    387         ListHashSetReverseIterator(const ListHashSetType* set, Node* position) : m_iterator(set, position) { }
    388 
    389     public:
    390         ListHashSetReverseIterator() { }
    391 
    392         // default copy, assignment and destructor are OK
    393 
    394         PointerType get() const { return const_cast<PointerType>(m_iterator.get()); }
    395         ReferenceType operator*() const { return *get(); }
    396         PointerType operator->() const { return get(); }
    397 
    398         reverse_iterator& operator++() { ++m_iterator; return *this; }
    399 
    400         // postfix ++ intentionally omitted
    401 
    402         reverse_iterator& operator--() { --m_iterator; return *this; }
    403 
    404         // postfix -- intentionally omitted
    405 
    406         // Comparison.
    407         bool operator==(const reverse_iterator& other) const { return m_iterator == other.m_iterator; }
    408         bool operator!=(const reverse_iterator& other) const { return m_iterator != other.m_iterator; }
    409 
    410         operator const_reverse_iterator() const { return m_iterator; }
    411 
    412     private:
    413         Node* node() { return m_iterator.node(); }
    414 
    415         const_reverse_iterator m_iterator;
    416     };
    417 
    418     template<typename ValueArg, size_t inlineCapacity, typename HashArg> class ListHashSetConstReverseIterator {
    419     private:
    420         typedef ListHashSet<ValueArg, inlineCapacity, HashArg> ListHashSetType;
    421         typedef ListHashSetReverseIterator<ValueArg, inlineCapacity, HashArg> reverse_iterator;
    422         typedef ListHashSetConstReverseIterator<ValueArg, inlineCapacity, HashArg> const_reverse_iterator;
    423         typedef ListHashSetNode<ValueArg, inlineCapacity> Node;
    424         typedef ValueArg ValueType;
    425         typedef const ValueType& ReferenceType;
    426         typedef const ValueType* PointerType;
    427 
    428         friend class ListHashSet<ValueArg, inlineCapacity, HashArg>;
    429         friend class ListHashSetReverseIterator<ValueArg, inlineCapacity, HashArg>;
    430 
    431         ListHashSetConstReverseIterator(const ListHashSetType* set, Node* position)
    432             : m_set(set)
    433             , m_position(position)
    434         {
    435         }
    436 
    437     public:
    438         ListHashSetConstReverseIterator()
    439         {
    440         }
    441 
    442         PointerType get() const
    443         {
    444             return &m_position->m_value;
    445         }
    446         ReferenceType operator*() const { return *get(); }
    447         PointerType operator->() const { return get(); }
    448 
    449         const_reverse_iterator& operator++()
    450         {
    451             ASSERT(m_position != 0);
    452             m_position = m_position->m_prev;
    453             return *this;
    454         }
    455 
    456         // postfix ++ intentionally omitted
    457 
    458         const_reverse_iterator& operator--()
    459         {
    460             ASSERT(m_position != m_set->m_tail);
    461             if (!m_position)
    462                 m_position = m_set->m_head;
    463             else
    464                 m_position = m_position->m_next;
    465             return *this;
    466         }
    467 
    468         // postfix -- intentionally omitted
    469 
    470         // Comparison.
    471         bool operator==(const const_reverse_iterator& other) const
    472         {
    473             return m_position == other.m_position;
    474         }
    475         bool operator!=(const const_reverse_iterator& other) const
    476         {
    477             return m_position != other.m_position;
    478         }
    479 
    480     private:
    481         Node* node() { return m_position; }
    482 
    483         const ListHashSetType* m_set;
    484         Node* m_position;
    485     };
    486 
    487383    template<typename ValueType, size_t inlineCapacity, typename HashFunctions>
    488384    struct ListHashSetTranslator {
     
    586482    inline typename ListHashSet<T, inlineCapacity, U>::reverse_iterator ListHashSet<T, inlineCapacity, U>::rbegin()
    587483    {
    588         return makeReverseIterator(m_tail);
     484        return reverse_iterator(end());
    589485    }
    590486
     
    592488    inline typename ListHashSet<T, inlineCapacity, U>::reverse_iterator ListHashSet<T, inlineCapacity, U>::rend()
    593489    {
    594         return makeReverseIterator(0);
     490        return reverse_iterator(begin());
    595491    }
    596492
     
    598494    inline typename ListHashSet<T, inlineCapacity, U>::const_reverse_iterator ListHashSet<T, inlineCapacity, U>::rbegin() const
    599495    {
    600         return makeConstReverseIterator(m_tail);
     496        return const_reverse_iterator(end());
    601497    }
    602498
     
    604500    inline typename ListHashSet<T, inlineCapacity, U>::const_reverse_iterator ListHashSet<T, inlineCapacity, U>::rend() const
    605501    {
    606         return makeConstReverseIterator(0);
     502        return const_reverse_iterator(begin());
    607503    }
    608504
     
    826722
    827723    template<typename T, size_t inlineCapacity, typename U>
    828     inline ListHashSetReverseIterator<T, inlineCapacity, U> ListHashSet<T, inlineCapacity, U>::makeReverseIterator(Node* position)
    829     {
    830         return ListHashSetReverseIterator<T, inlineCapacity, U>(this, position);
    831     }
    832 
    833     template<typename T, size_t inlineCapacity, typename U>
    834     inline ListHashSetConstReverseIterator<T, inlineCapacity, U> ListHashSet<T, inlineCapacity, U>::makeConstReverseIterator(Node* position) const
    835     {
    836         return ListHashSetConstReverseIterator<T, inlineCapacity, U>(this, position);
    837     }
    838    
    839     template<typename T, size_t inlineCapacity, typename U>
    840724    inline ListHashSetIterator<T, inlineCapacity, U> ListHashSet<T, inlineCapacity, U>::makeIterator(Node* position)
    841725    {
Note: See TracChangeset for help on using the changeset viewer.