This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

stl_bvector.h cleanup


Approved by Ben, tested on alpha, applied to trunk.


r~


        * include/bits/stl_bvector.h (_Bit_type): New.  Use throughout.

Index: libstdc++-v3/include/bits/stl_bvector.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_bvector.h,v
retrieving revision 1.12
diff -c -p -d -r1.12 stl_bvector.h
*** stl_bvector.h	2002/03/07 06:53:21	1.12
--- stl_bvector.h	2002/03/11 22:34:10
***************
*** 63,79 ****
  
  namespace std
  { 
!   enum { _M_word_bit = int(CHAR_BIT * sizeof(unsigned long)) };
  
  struct _Bit_reference {
!   unsigned int* _M_p;
!   unsigned int _M_mask;
!   _Bit_reference(unsigned int* __x, unsigned int __y) 
      : _M_p(__x), _M_mask(__y) {}
  
  public:
    _Bit_reference() : _M_p(0), _M_mask(0) {}
!   operator bool() const { return !(!(*_M_p & _M_mask)); }
    _Bit_reference& operator=(bool __x)
    {
      if (__x)  *_M_p |= _M_mask;
--- 63,81 ----
  
  namespace std
  { 
!   typedef unsigned long _Bit_type;
!   enum { _M_word_bit = int(CHAR_BIT * sizeof(_Bit_type)) };
  
  struct _Bit_reference {
! 
!   _Bit_type * _M_p;
!   _Bit_type _M_mask;
!   _Bit_reference(_Bit_type * __x, _Bit_type __y) 
      : _M_p(__x), _M_mask(__y) {}
  
  public:
    _Bit_reference() : _M_p(0), _M_mask(0) {}
!   operator bool() const { return !!(*_M_p & _M_mask); }
    _Bit_reference& operator=(bool __x)
    {
      if (__x)  *_M_p |= _M_mask;
*************** public:
*** 84,92 ****
      { return *this = bool(__x); }
    bool operator==(const _Bit_reference& __x) const
      { return bool(*this) == bool(__x); }
!   bool operator<(const _Bit_reference& __x) const {
!     return !bool(*this) && bool(__x);
!   }
    void flip() { *_M_p ^= _M_mask; }
  };
  
--- 86,93 ----
      { return *this = bool(__x); }
    bool operator==(const _Bit_reference& __x) const
      { return bool(*this) == bool(__x); }
!   bool operator<(const _Bit_reference& __x) const
!     { return !bool(*this) && bool(__x); }
    void flip() { *_M_p ^= _M_mask; }
  };
  
*************** inline void swap(_Bit_reference __x, _Bi
*** 99,108 ****
  
  struct _Bit_iterator_base : public iterator<random_access_iterator_tag, bool>
  {
!   unsigned int* _M_p;
    unsigned int _M_offset;
  
!   _Bit_iterator_base(unsigned int* __x, unsigned int __y)
      : _M_p(__x), _M_offset(__y) {}
  
    void _M_bump_up() {
--- 100,109 ----
  
  struct _Bit_iterator_base : public iterator<random_access_iterator_tag, bool>
  {
!   _Bit_type * _M_p;
    unsigned int _M_offset;
  
!   _Bit_iterator_base(_Bit_type * __x, unsigned int __y)
      : _M_p(__x), _M_offset(__y) {}
  
    void _M_bump_up() {
*************** struct _Bit_iterator : public _Bit_itera
*** 162,168 ****
    typedef _Bit_iterator   iterator;
  
    _Bit_iterator() : _Bit_iterator_base(0, 0) {}
!   _Bit_iterator(unsigned int* __x, unsigned int __y) 
      : _Bit_iterator_base(__x, __y) {}
  
    reference operator*() const { return reference(_M_p, 1U << _M_offset); }
--- 163,169 ----
    typedef _Bit_iterator   iterator;
  
    _Bit_iterator() : _Bit_iterator_base(0, 0) {}
!   _Bit_iterator(_Bit_type * __x, unsigned int __y) 
      : _Bit_iterator_base(__x, __y) {}
  
    reference operator*() const { return reference(_M_p, 1U << _M_offset); }
*************** struct _Bit_const_iterator : public _Bit
*** 216,222 ****
    typedef _Bit_const_iterator  const_iterator;
  
    _Bit_const_iterator() : _Bit_iterator_base(0, 0) {}
!   _Bit_const_iterator(unsigned int* __x, unsigned int __y) 
      : _Bit_iterator_base(__x, __y) {}
    _Bit_const_iterator(const _Bit_iterator& __x) 
      : _Bit_iterator_base(__x._M_p, __x._M_offset) {}
--- 217,223 ----
    typedef _Bit_const_iterator  const_iterator;
  
    _Bit_const_iterator() : _Bit_iterator_base(0, 0) {}
!   _Bit_const_iterator(_Bit_type * __x, unsigned int __y) 
      : _Bit_iterator_base(__x, __y) {}
    _Bit_const_iterator(const _Bit_iterator& __x) 
      : _Bit_iterator_base(__x._M_p, __x._M_offset) {}
*************** public:
*** 282,288 ****
      : _M_data_allocator(__a), _M_start(), _M_finish(), _M_end_of_storage(0) {}
  
  protected:
!   unsigned int* _M_bit_alloc(size_t __n) 
      { return _M_data_allocator.allocate((__n + _M_word_bit - 1)/_M_word_bit); }
    void _M_deallocate() {
      if (_M_start._M_p)
--- 283,289 ----
      : _M_data_allocator(__a), _M_start(), _M_finish(), _M_end_of_storage(0) {}
  
  protected:
!   _Bit_type * _M_bit_alloc(size_t __n) 
      { return _M_data_allocator.allocate((__n + _M_word_bit - 1)/_M_word_bit); }
    void _M_deallocate() {
      if (_M_start._M_p)
*************** protected:
*** 290,300 ****
                                     _M_end_of_storage - _M_start._M_p);
    }  
  
!   typename _Alloc_traits<unsigned int, _Allocator>::allocator_type 
            _M_data_allocator;
    _Bit_iterator _M_start;
    _Bit_iterator _M_finish;
!   unsigned int* _M_end_of_storage;
  };
  
  // Specialization for instanceless allocators.
--- 291,301 ----
                                     _M_end_of_storage - _M_start._M_p);
    }  
  
!   typename _Alloc_traits<_Bit_type, _Allocator>::allocator_type 
            _M_data_allocator;
    _Bit_iterator _M_start;
    _Bit_iterator _M_finish;
!   _Bit_type * _M_end_of_storage;
  };
  
  // Specialization for instanceless allocators.
*************** public:
*** 309,318 ****
      : _M_start(), _M_finish(), _M_end_of_storage(0) {}
  
  protected:
!   typedef typename _Alloc_traits<unsigned int, _Allocator>::_Alloc_type
            _Alloc_type;
            
!   unsigned int* _M_bit_alloc(size_t __n) 
      { return _Alloc_type::allocate((__n + _M_word_bit - 1)/_M_word_bit); }
    void _M_deallocate() {
      if (_M_start._M_p)
--- 310,319 ----
      : _M_start(), _M_finish(), _M_end_of_storage(0) {}
  
  protected:
!   typedef typename _Alloc_traits<_Bit_type, _Allocator>::_Alloc_type
            _Alloc_type;
            
!   _Bit_type * _M_bit_alloc(size_t __n) 
      { return _Alloc_type::allocate((__n + _M_word_bit - 1)/_M_word_bit); }
    void _M_deallocate() {
      if (_M_start._M_p)
*************** protected:
*** 322,328 ****
  
    _Bit_iterator _M_start;
    _Bit_iterator _M_finish;
!   unsigned int* _M_end_of_storage;
  };  
  
  template <class _Alloc>
--- 323,329 ----
  
    _Bit_iterator _M_start;
    _Bit_iterator _M_finish;
!   _Bit_type * _M_end_of_storage;
  };  
  
  template <class _Alloc>
*************** template <typename _Alloc> 
*** 379,385 ****
    
    protected:
      void _M_initialize(size_type __n) {
!       unsigned int* __q = _M_bit_alloc(__n);
        _M_end_of_storage = __q + (__n + _M_word_bit - 1)/_M_word_bit;
        _M_start = iterator(__q, 0);
        _M_finish = _M_start + difference_type(__n);
--- 380,386 ----
    
    protected:
      void _M_initialize(size_type __n) {
!       _Bit_type * __q = _M_bit_alloc(__n);
        _M_end_of_storage = __q + (__n + _M_word_bit - 1)/_M_word_bit;
        _M_start = iterator(__q, 0);
        _M_finish = _M_start + difference_type(__n);
*************** template <typename _Alloc> 
*** 392,398 ****
        }
        else {
          size_type __len = size() ? 2 * size() : _M_word_bit;
!         unsigned int* __q = _M_bit_alloc(__len);
          iterator __i = copy(begin(), __position, iterator(__q, 0));
          *__i++ = __x;
          _M_finish = copy(__position, end(), __i);
--- 393,399 ----
        }
        else {
          size_type __len = size() ? 2 * size() : _M_word_bit;
!         _Bit_type * __q = _M_bit_alloc(__len);
          iterator __i = copy(begin(), __position, iterator(__q, 0));
          *__i++ = __x;
          _M_finish = copy(__position, end(), __i);
*************** template <typename _Alloc> 
*** 443,449 ****
          }
          else {
            size_type __len = size() + max(size(), __n);
!           unsigned int* __q = _M_bit_alloc(__len);
            iterator __i = copy(begin(), __position, iterator(__q, 0));
            __i = copy(__first, __last, __i);
            _M_finish = copy(__position, end(), __i);
--- 444,450 ----
          }
          else {
            size_type __len = size() + max(size(), __n);
!           _Bit_type * __q = _M_bit_alloc(__len);
            iterator __i = copy(begin(), __position, iterator(__q, 0));
            __i = copy(__first, __last, __i);
            _M_finish = copy(__position, end(), __i);
*************** template <typename _Alloc> 
*** 610,616 ****
    
      void reserve(size_type __n) {
        if (capacity() < __n) {
!         unsigned int* __q = _M_bit_alloc(__n);
          _M_finish = copy(begin(), end(), iterator(__q, 0));
          _M_deallocate();
          _M_start = iterator(__q, 0);
--- 611,617 ----
    
      void reserve(size_type __n) {
        if (capacity() < __n) {
!         _Bit_type * __q = _M_bit_alloc(__n);
          _M_finish = copy(begin(), end(), iterator(__q, 0));
          _M_deallocate();
          _M_start = iterator(__q, 0);
*************** template <typename _Alloc> 
*** 673,679 ****
        }
        else {
          size_type __len = size() + max(size(), __n);
!         unsigned int* __q = _M_bit_alloc(__len);
          iterator __i = copy(begin(), __position, iterator(__q, 0));
          fill_n(__i, __n, __x);
          _M_finish = copy(__position, end(), __i + difference_type(__n));
--- 674,680 ----
        }
        else {
          size_type __len = size() + max(size(), __n);
!         _Bit_type * __q = _M_bit_alloc(__len);
          iterator __i = copy(begin(), __position, iterator(__q, 0));
          fill_n(__i, __n, __x);
          _M_finish = copy(__position, end(), __i + difference_type(__n));
*************** template <typename _Alloc> 
*** 705,711 ****
          insert(end(), __new_size - size(), __x);
      }
      void flip() {
!       for (unsigned int* __p = _M_start._M_p; __p != _M_end_of_storage; ++__p)
          *__p = ~*__p;
      }
    
--- 706,712 ----
          insert(end(), __new_size - size(), __x);
      }
      void flip() {
!       for (_Bit_type * __p = _M_start._M_p; __p != _M_end_of_storage; ++__p)
          *__p = ~*__p;
      }
    


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]