This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


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

[patch] string inlines



Some of the basic_string<> members have grown enough that they
shouldn't be inline any more.  

(Not tested, sorry.  Tell me if it doesn't work and I'll do my
homework better before submitting again.)

Nathan Myers
ncm@nospam.cantrip.org

------
Index: basic_string.h
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/basic_string.h,v
retrieving revision 1.55
diff -u -r1.55 basic_string.h
--- basic_string.h	2000/03/21 06:24:04	1.55
+++ basic_string.h	2000/03/27 08:38:30
@@ -457,53 +457,20 @@
       operator+=(_CharT __c) { return this->append(size_type(1), __c); }
 
       basic_string& 
-      append(const basic_string& __str)
-      { 
-	// Iff appending itself, string needs to pre-reserve the
-	// correct size so that _M_mutate does not clobber the
-	// iterators formed here.
-	size_type __size = __str.size();
-	size_type __len = __size + this->size();
-	if (__len > this->capacity())
-	  this->reserve(__len); 
-	return this->replace(_M_iend(), _M_iend(), __str._M_ibegin(),
-			     __str._M_iend());
-      }
+      append(const basic_string& __str);
 
       basic_string& 
-      append(const basic_string& __str, size_type __pos, size_type __n)
-      { 
-	// Iff appending itself, string needs to pre-reserve the
-	// correct size so that _M_mutate does not clobber the
-	// iterators formed here.
-	size_type __len = min(__str.size() - __pos, __n) + this->size();
-	if (__len > this->capacity())
-	  this->reserve(__len); 
-	return this->replace(_M_iend(), _M_iend(), __str._M_check(__pos),
-			     __str._M_fold(__pos, __n)); 
-      }
+      append(const basic_string& __str, size_type __pos, size_type __n);
 
       basic_string& 
-      append(const _CharT* __s, size_type __n)
-      {
-	size_type __len = __n + this->size();
-	if (__len > this->capacity())
-	  this->reserve(__len); 
-	return this->replace(_M_iend(), _M_iend(), __s, __s + __n); 
-      }
+      append(const _CharT* __s, size_type __n);
 
       basic_string& 
       append(const _CharT* __s)
       { return this->append(__s, traits_type::length(__s)); }
 
       basic_string& 
-      append(size_type __n, _CharT __c)
-      { 
-	size_type __len = __n + this->size();
-	if (__len > this->capacity())
-	  this->reserve(__len); 
-	return this->replace(_M_iend(), _M_iend(), __n, __c); 
-      }
+      append(size_type __n, _CharT __c);
 
       template<class _InputIterator>
         basic_string& 
@@ -898,31 +865,13 @@
     }
 
   template<typename _CharT, typename _Traits, typename _Alloc>
-    inline basic_string<_CharT, _Traits, _Alloc>
+    basic_string<_CharT,_Traits,_Alloc>
     operator+(const _CharT* __lhs,
-	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
-    {
-      typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
-      __string_type::size_type __len = _Traits::length(__lhs);
-      __string_type __str;
-      __str.reserve(__len + __rhs.size());
-      __str.append(__lhs, __lhs + __len);
-      __str.append(__rhs);
-      return __str;
-    }
+	      const basic_string<_CharT,_Traits,_Alloc>& __rhs);
 
   template<typename _CharT, typename _Traits, typename _Alloc>
-    inline basic_string<_CharT, _Traits, _Alloc>
-    operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
-    {
-      typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
-      __string_type __str;
-      __string_type::size_type __len = __rhs.size();
-      __str.reserve(__len + 1);
-      __str.append(__string_type::size_type(1), __lhs);
-      __str.append(__rhs);
-      return __str;
-    }
+    basic_string<_CharT,_Traits,_Alloc>
+    operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
 
   template<typename _CharT, typename _Traits, typename _Alloc>
     inline basic_string<_CharT, _Traits, _Alloc>
Index: string.tcc
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/string.tcc,v
retrieving revision 1.58
diff -u -r1.58 string.tcc
--- string.tcc	2000/03/21 06:24:04	1.58
+++ string.tcc	2000/03/27 08:38:45
@@ -415,6 +415,85 @@
 	this->erase(__n);
       // else nothing (in particular, avoid calling _M_mutate() unnecessarily.)
     }
+
+  template<typename _CharT, typename _Traits, typename _Alloc>
+      basic_string<_CharT,_Traits,_Alloc>& 
+      basic_string<_CharT,_Traits,_Alloc>::append(const basic_string& __str)
+      { 
+	// Iff appending itself, string needs to pre-reserve the
+	// correct size so that _M_mutate does not clobber the
+	// iterators formed here.
+	size_type __size = __str.size();
+	size_type __len = __size + this->size();
+	if (__len > this->capacity())
+	  this->reserve(__len); 
+	return this->replace(_M_iend(), _M_iend(), __str._M_ibegin(),
+			     __str._M_iend());
+      }
+
+  template<typename _CharT, typename _Traits, typename _Alloc>
+      basic_string<_CharT,_Traits,_Alloc>& 
+      basic_string<_CharT,_Traits,_Alloc>::append(
+        const basic_string& __str, size_type __pos, size_type __n)
+      { 
+	// Iff appending itself, string needs to pre-reserve the
+	// correct size so that _M_mutate does not clobber the
+	// iterators formed here.
+	size_type __len = min(__str.size() - __pos, __n) + this->size();
+	if (__len > this->capacity())
+	  this->reserve(__len); 
+	return this->replace(_M_iend(), _M_iend(), __str._M_check(__pos),
+			     __str._M_fold(__pos, __n)); 
+      }
+
+  template<typename _CharT, typename _Traits, typename _Alloc>
+      basic_string<_CharT,_Traits,_Alloc>& 
+      basic_string<_CharT,_Traits,_Alloc>::append(
+        const _CharT* __s, size_type __n)
+      {
+	size_type __len = __n + this->size();
+	if (__len > this->capacity())
+	  this->reserve(__len); 
+	return this->replace(_M_iend(), _M_iend(), __s, __s + __n); 
+      }
+
+  template<typename _CharT, typename _Traits, typename _Alloc>
+      basic_string<_CharT,_Traits,_Alloc>& 
+      basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c)
+      { 
+	size_type __len = __n + this->size();
+	if (__len > this->capacity())
+	  this->reserve(__len); 
+	return this->replace(_M_iend(), _M_iend(), __n, __c); 
+      }
+
+  template<typename _CharT, typename _Traits, typename _Alloc>
+    basic_string<_CharT,_Traits,_Alloc>
+    operator+(const _CharT* __lhs,
+	      const basic_string<_CharT,_Traits,_Alloc>& __rhs)
+    {
+      typedef basic_string<_CharT,_Traits,_Alloc> __string_type;
+      __string_type::size_type __len = _Traits::length(__lhs);
+      __string_type __str;
+      __str.reserve(__len + __rhs.size());
+      __str.append(__lhs, __lhs + __len);
+      __str.append(__rhs);
+      return __str;
+    }
+
+  template<typename _CharT, typename _Traits, typename _Alloc>
+    basic_string<_CharT,_Traits,_Alloc>
+    operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
+    {
+      typedef basic_string<_CharT,_Traits,_Alloc> __string_type;
+      __string_type __str;
+      __string_type::size_type __len = __rhs.size();
+      __str.reserve(__len + 1);
+      __str.append(__string_type::size_type(1), __lhs);
+      __str.append(__rhs);
+      return __str;
+    }
+
   
   template<typename _CharT, typename _Traits, typename _Alloc>
     template<typename _InputIter>


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