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]

[v3] Basic_string: minor tweaks


Hi,

tested x86-linux, applied to mainline.

Paolo.

///////////////
2004-01-31  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/basic_string.tcc (_Rep::_S_create): Minor tweak.
2004-01-31  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/basic_string.h (_Rep::operator[]): Remove, unused.

	* include/bits/basic_string.h: Fix two comments.
diff -urN libstdc++-v3-orig/include/bits/basic_string.tcc libstdc++-v3/include/bits/basic_string.tcc
--- libstdc++-v3-orig/include/bits/basic_string.tcc	2004-01-30 14:03:49.000000000 +0100
+++ libstdc++-v3/include/bits/basic_string.tcc	2004-01-31 16:33:24.000000000 +0100
@@ -514,11 +514,10 @@
       // Whew. Seemingly so needy, yet so elemental.
       size_type __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
 
-      if (__size + __malloc_header_size > __pagesize)
+      const size_type __adj_size = __size + __malloc_header_size;
+      if (__adj_size > __pagesize)
 	{
-	  const size_type __extra = (__pagesize
-				     - (__size + __malloc_header_size)
-				     % __pagesize);
+	  const size_type __extra = __pagesize - __adj_size % __pagesize;
 	  __capacity += __extra / sizeof(_CharT);
 	  // Never allocate a string bigger than _S_max_size.
 	  if (__capacity > _S_max_size)
@@ -527,9 +526,7 @@
 	}
       else if (__size > __subpagesize)
 	{
-	  const size_type __extra = (__subpagesize
-				     - (__size + __malloc_header_size)
-				     % __subpagesize);
+	  const size_type __extra = __subpagesize - __adj_size % __subpagesize;
 	  __capacity += __extra / sizeof(_CharT);
 	  __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
 	}
diff -urN libstdc++-v3-orig/include/bits/basic_string.h libstdc++-v3/include/bits/basic_string.h
--- libstdc++-v3-orig/include/bits/basic_string.h	2004-01-28 11:37:31.000000000 +0100
+++ libstdc++-v3/include/bits/basic_string.h	2004-01-31 18:16:49.000000000 +0100
@@ -132,7 +132,7 @@
       //   1. String really contains _M_length + 1 characters: due to 21.3.4
       //      must be kept null-terminated.
       //   2. _M_capacity >= _M_length
-      //      Allocated memory is always _M_capacity + (1 * sizeof(_CharT)).
+      //      Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
       //   3. _M_refcount has three states:
       //      -1: leaked, one reference, no ref-copies allowed, non-const.
       //       0: one reference, non-const.
@@ -197,10 +197,6 @@
 	_M_refdata() throw()
 	{ return reinterpret_cast<_CharT*>(this + 1); }
 
-	_CharT&
-	operator[](size_type __s) throw()
-	{ return _M_refdata() [__s]; }
-
 	_CharT*
 	_M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
 	{
@@ -1460,8 +1456,8 @@
       /**
        *  @brief  Return const pointer to contents.
        *
-       *  This is a handle to internal data.  It may not be null-terminated.
-       *  Do not modify or dire things may happen.
+       *  This is a handle to internal data.  Do not modify or dire things may
+       *  happen.
       */
       const _CharT*
       data() const { return _M_data(); }

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