]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/bits/vector.tcc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / vector.tcc
index 1d1ef427b26d99a4d817c3dfeb10f8a4374d520e..27e63388feb1f950187a756b52ae753b29715f86 100644 (file)
@@ -1,6 +1,6 @@
 // Vector implementation (out of line) -*- C++ -*-
 
-// Copyright (C) 2001-2018 Free Software Foundation, Inc.
+// Copyright (C) 2001-2020 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -71,12 +71,24 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       if (this->capacity() < __n)
        {
          const size_type __old_size = size();
-         pointer __tmp = _M_allocate_and_copy(__n,
-           _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start),
-           _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish));
+         pointer __tmp;
+#if __cplusplus >= 201103L
+         if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
+           {
+             __tmp = this->_M_allocate(__n);
+             _S_relocate(this->_M_impl._M_start, this->_M_impl._M_finish,
+                         __tmp, _M_get_Tp_allocator());
+           }
+         else
+#endif
+           {
+             __tmp = _M_allocate_and_copy(__n,
+               _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start),
+               _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish));
+             std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
+                           _M_get_Tp_allocator());
+           }
          _GLIBCXX_ASAN_ANNOTATE_REINIT;
-         std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
-                       _M_get_Tp_allocator());
          _M_deallocate(this->_M_impl._M_start,
                        this->_M_impl._M_end_of_storage
                        - this->_M_impl._M_start);
@@ -293,10 +305,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
        if (__len > capacity())
          {
+           _S_check_init_len(__len, _M_get_Tp_allocator());
            pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
-           _GLIBCXX_ASAN_ANNOTATE_REINIT;
            std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                          _M_get_Tp_allocator());
+           _GLIBCXX_ASAN_ANNOTATE_REINIT;
            _M_deallocate(this->_M_impl._M_start,
                          this->_M_impl._M_end_of_storage
                          - this->_M_impl._M_start);
@@ -442,17 +455,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 #endif
          __new_finish = pointer();
 
-         __new_finish
-           = std::__uninitialized_move_if_noexcept_a
-           (__old_start, __position.base(),
-            __new_start, _M_get_Tp_allocator());
+#if __cplusplus >= 201103L
+         if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
+           {
+             __new_finish = _S_relocate(__old_start, __position.base(),
+                                        __new_start, _M_get_Tp_allocator());
+
+             ++__new_finish;
+
+             __new_finish = _S_relocate(__position.base(), __old_finish,
+                                        __new_finish, _M_get_Tp_allocator());
+           }
+         else
+#endif
+           {
+             __new_finish
+               = std::__uninitialized_move_if_noexcept_a
+               (__old_start, __position.base(),
+                __new_start, _M_get_Tp_allocator());
 
-         ++__new_finish;
+             ++__new_finish;
 
-         __new_finish
-           = std::__uninitialized_move_if_noexcept_a
-           (__position.base(), __old_finish,
-            __new_finish, _M_get_Tp_allocator());
+             __new_finish
+               = std::__uninitialized_move_if_noexcept_a
+               (__position.base(), __old_finish,
+                __new_finish, _M_get_Tp_allocator());
+           }
        }
       __catch(...)
        {
@@ -464,8 +492,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
          _M_deallocate(__new_start, __len);
          __throw_exception_again;
        }
+#if __cplusplus >= 201103L
+      if _GLIBCXX17_CONSTEXPR (!_S_use_relocate())
+#endif
+       std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator());
       _GLIBCXX_ASAN_ANNOTATE_REINIT;
-      std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator());
       _M_deallocate(__old_start,
                    this->_M_impl._M_end_of_storage - __old_start);
       this->_M_impl._M_start = __new_start;
@@ -561,9 +592,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
                  _M_deallocate(__new_start, __len);
                  __throw_exception_again;
                }
-             _GLIBCXX_ASAN_ANNOTATE_REINIT;
              std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                            _M_get_Tp_allocator());
+             _GLIBCXX_ASAN_ANNOTATE_REINIT;
              _M_deallocate(this->_M_impl._M_start,
                            this->_M_impl._M_end_of_storage
                            - this->_M_impl._M_start);
@@ -582,7 +613,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     {
       if (__n != 0)
        {
-         size_type __size = size();
+         const size_type __size = size();
          size_type __navail = size_type(this->_M_impl._M_end_of_storage
                                         - this->_M_impl._M_finish);
 
@@ -601,34 +632,51 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
            {
              const size_type __len =
                _M_check_len(__n, "vector::_M_default_append");
-             const size_type __old_size = __size;
              pointer __new_start(this->_M_allocate(__len));
-             pointer __new_finish(__new_start);
-             __try
+             if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
                {
-                 __new_finish
-                   = std::__uninitialized_move_if_noexcept_a
-                   (this->_M_impl._M_start, this->_M_impl._M_finish,
-                    __new_start, _M_get_Tp_allocator());
-                 __new_finish =
-                   std::__uninitialized_default_n_a(__new_finish, __n,
-                                                    _M_get_Tp_allocator());
+                 __try
+                   {
+                     std::__uninitialized_default_n_a(__new_start + __size,
+                             __n, _M_get_Tp_allocator());
+                   }
+                 __catch(...)
+                   {
+                     _M_deallocate(__new_start, __len);
+                     __throw_exception_again;
+                   }
+                 _S_relocate(this->_M_impl._M_start, this->_M_impl._M_finish,
+                             __new_start, _M_get_Tp_allocator());
                }
-             __catch(...)
+             else
                {
-                 std::_Destroy(__new_start, __new_finish,
+                 pointer __destroy_from = pointer();
+                 __try
+                   {
+                     std::__uninitialized_default_n_a(__new_start + __size,
+                             __n, _M_get_Tp_allocator());
+                     __destroy_from = __new_start + __size;
+                     std::__uninitialized_move_if_noexcept_a(
+                             this->_M_impl._M_start, this->_M_impl._M_finish,
+                             __new_start, _M_get_Tp_allocator());
+                   }
+                 __catch(...)
+                   {
+                     if (__destroy_from)
+                       std::_Destroy(__destroy_from, __destroy_from + __n,
+                                     _M_get_Tp_allocator());
+                     _M_deallocate(__new_start, __len);
+                     __throw_exception_again;
+                   }
+                 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                                _M_get_Tp_allocator());
-                 _M_deallocate(__new_start, __len);
-                 __throw_exception_again;
                }
              _GLIBCXX_ASAN_ANNOTATE_REINIT;
-             std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
-                           _M_get_Tp_allocator());
              _M_deallocate(this->_M_impl._M_start,
                            this->_M_impl._M_end_of_storage
                            - this->_M_impl._M_start);
              this->_M_impl._M_start = __new_start;
-             this->_M_impl._M_finish = __new_finish;
+             this->_M_impl._M_finish = __new_start + __size + __n;
              this->_M_impl._M_end_of_storage = __new_start + __len;
            }
        }
@@ -742,9 +790,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
                    _M_deallocate(__new_start, __len);
                    __throw_exception_again;
                  }
-               _GLIBCXX_ASAN_ANNOTATE_REINIT;
                std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                              _M_get_Tp_allocator());
+               _GLIBCXX_ASAN_ANNOTATE_REINIT;
                _M_deallocate(this->_M_impl._M_start,
                              this->_M_impl._M_end_of_storage
                              - this->_M_impl._M_start);