public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-3871] libstdc++: Define some std::string constructors inline
@ 2020-10-14 11:53 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2020-10-14 11:53 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:252c9967ba785aedf3b39e2cd50237d0f32fe3bd

commit r11-3871-g252c9967ba785aedf3b39e2cd50237d0f32fe3bd
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Oct 14 12:10:26 2020 +0100

    libstdc++: Define some std::string constructors inline
    
    There are a lot of very simple constructors for the old string which are
    not defined inline. I don't see any reason for this and it probably
    makes them less likely to be optimized away. Move the definitions into
    the class body.
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/basic_string.h (basic_string(const Alloc&))
            (basic_string(const basic_string&)
            (basic_string(const CharT*, size_type, const Alloc&))
            (basic_string(const CharT*, const Alloc&))
            (basic_string(size_type, CharT, const Alloc&))
            (basic_string(initializer_list<CharT>, const Alloc&))
            (basic_string(InputIterator, InputIterator, const Alloc&)):
            Define inline in class body.
            * include/bits/basic_string.tcc (basic_string(const Alloc&))
            (basic_string(const basic_string&)
            (basic_string(const CharT*, size_type, const Alloc&))
            (basic_string(const CharT*, const Alloc&))
            (basic_string(size_type, CharT, const Alloc&))
            (basic_string(initializer_list<CharT>, const Alloc&))
            (basic_string(InputIterator, InputIterator, const Alloc&)):
            Move definitions into class body.

Diff:
---
 libstdc++-v3/include/bits/basic_string.h   | 39 ++++++++++++++++-------
 libstdc++-v3/include/bits/basic_string.tcc | 51 ------------------------------
 2 files changed, 28 insertions(+), 62 deletions(-)

diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 4b3722bdbf1..372302ba6a1 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -548,7 +548,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
        *
        *  The newly-created string contains the exact contents of @a __str.
        *  @a __str is a valid, but unspecified string.
-       **/
+       */
       basic_string(basic_string&& __str) noexcept
       : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator()))
       {
@@ -696,7 +696,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
        *
        *  The contents of @a str are moved into this string (without copying).
        *  @a str is a valid, but unspecified string.
-       **/
+       */
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 2063. Contradictory requirements for string move assignment
       basic_string&
@@ -3563,14 +3563,20 @@ _GLIBCXX_END_NAMESPACE_CXX11
        *  @brief  Construct an empty string using allocator @a a.
        */
       explicit
-      basic_string(const _Alloc& __a);
+      basic_string(const _Alloc& __a)
+      : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
+      { }
 
       // NB: per LWG issue 42, semantics different from IS:
       /**
        *  @brief  Construct string with copy of value of @a str.
        *  @param  __str  Source string.
        */
-      basic_string(const basic_string& __str);
+      basic_string(const basic_string& __str)
+      : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.get_allocator()),
+					    __str.get_allocator()),
+		    __str.get_allocator())
+      { }
 
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 2583. no way to supply an allocator for basic_string(str, pos)
@@ -3611,7 +3617,9 @@ _GLIBCXX_END_NAMESPACE_CXX11
        *  has no special meaning.
        */
       basic_string(const _CharT* __s, size_type __n,
-		   const _Alloc& __a = _Alloc());
+		   const _Alloc& __a = _Alloc())
+      : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
+      { }
 
       /**
        *  @brief  Construct string as copy of a C string.
@@ -3623,7 +3631,10 @@ _GLIBCXX_END_NAMESPACE_CXX11
       // 3076. basic_string CTAD ambiguity
       template<typename = _RequireAllocator<_Alloc>>
 #endif
-      basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
+      basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
+      : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
+				 __s + npos, __a), __a)
+      { }
 
       /**
        *  @brief  Construct string as multiple characters.
@@ -3631,7 +3642,9 @@ _GLIBCXX_END_NAMESPACE_CXX11
        *  @param  __c  Character to use.
        *  @param  __a  Allocator to use (default is default allocator).
        */
-      basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
+      basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
+      : _M_dataplus(_S_construct(__n, __c, __a), __a)
+      { }
 
 #if __cplusplus >= 201103L
       /**
@@ -3640,7 +3653,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        *
        *  The newly-created string contains the exact contents of @a __str.
        *  @a __str is a valid, but unspecified string.
-       **/
+       */
       basic_string(basic_string&& __str)
 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
       noexcept // FIXME C++11: should always be noexcept.
@@ -3659,7 +3672,9 @@ _GLIBCXX_END_NAMESPACE_CXX11
        *  @param  __l  std::initializer_list of characters.
        *  @param  __a  Allocator to use (default is default allocator).
        */
-      basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc());
+      basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
+      : _M_dataplus(_S_construct(__l.begin(), __l.end(), __a), __a)
+      { }
 
       basic_string(const basic_string& __str, const _Alloc& __a)
       : _M_dataplus(__str._M_rep()->_M_grab(__a, __str.get_allocator()), __a)
@@ -3689,7 +3704,9 @@ _GLIBCXX_END_NAMESPACE_CXX11
        */
       template<class _InputIterator>
         basic_string(_InputIterator __beg, _InputIterator __end,
-		     const _Alloc& __a = _Alloc());
+		     const _Alloc& __a = _Alloc())
+	: _M_dataplus(_S_construct(__beg, __end, __a), __a)
+	{ }
 
 #if __cplusplus >= 201703L
       /**
@@ -3758,7 +3775,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        *
        *  The contents of @a str are moved into this string (without copying).
        *  @a str is a valid, but unspecified string.
-       **/
+       */
       basic_string&
       operator=(basic_string&& __str)
       _GLIBCXX_NOEXCEPT_IF(allocator_traits<_Alloc>::is_always_equal::value)
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc
index 95d2fdbd6d6..6c789665160 100644
--- a/libstdc++-v3/include/bits/basic_string.tcc
+++ b/libstdc++-v3/include/bits/basic_string.tcc
@@ -632,20 +632,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return __r->_M_refdata();
     }
 
-  template<typename _CharT, typename _Traits, typename _Alloc>
-    basic_string<_CharT, _Traits, _Alloc>::
-    basic_string(const basic_string& __str)
-    : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.get_allocator()),
-					  __str.get_allocator()),
-		  __str.get_allocator())
-    { }
-
-  template<typename _CharT, typename _Traits, typename _Alloc>
-    basic_string<_CharT, _Traits, _Alloc>::
-    basic_string(const _Alloc& __a)
-    : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
-    { }
-
   template<typename _CharT, typename _Traits, typename _Alloc>
     basic_string<_CharT, _Traits, _Alloc>::
     basic_string(const basic_string& __str, size_type __pos, const _Alloc& __a)
@@ -677,43 +663,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 			       + __pos, __a), __a)
     { }
 
-  // TBD: DPG annotate
-  template<typename _CharT, typename _Traits, typename _Alloc>
-    basic_string<_CharT, _Traits, _Alloc>::
-    basic_string(const _CharT* __s, size_type __n, const _Alloc& __a)
-    : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
-    { }
-
-  // TBD: DPG annotate
-  template<typename _CharT, typename _Traits, typename _Alloc>
-    basic_string<_CharT, _Traits, _Alloc>::
-    basic_string(const _CharT* __s, const _Alloc& __a)
-    : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
-			       __s + npos, __a), __a)
-    { }
-
-  template<typename _CharT, typename _Traits, typename _Alloc>
-    basic_string<_CharT, _Traits, _Alloc>::
-    basic_string(size_type __n, _CharT __c, const _Alloc& __a)
-    : _M_dataplus(_S_construct(__n, __c, __a), __a)
-    { }
-
-  // TBD: DPG annotate
-  template<typename _CharT, typename _Traits, typename _Alloc>
-    template<typename _InputIterator>
-    basic_string<_CharT, _Traits, _Alloc>::
-    basic_string(_InputIterator __beg, _InputIterator __end, const _Alloc& __a)
-    : _M_dataplus(_S_construct(__beg, __end, __a), __a)
-    { }
-
-#if __cplusplus >= 201103L
-  template<typename _CharT, typename _Traits, typename _Alloc>
-    basic_string<_CharT, _Traits, _Alloc>::
-    basic_string(initializer_list<_CharT> __l, const _Alloc& __a)
-    : _M_dataplus(_S_construct(__l.begin(), __l.end(), __a), __a)
-    { }
-#endif
-
   template<typename _CharT, typename _Traits, typename _Alloc>
     basic_string<_CharT, _Traits, _Alloc>&
     basic_string<_CharT, _Traits, _Alloc>::


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-14 11:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 11:53 [gcc r11-3871] libstdc++: Define some std::string constructors inline Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).