components/gcc49/patches/026-basic_string.patch
author Stefan Teleman <stefan.teleman@oracle.com>
Wed, 16 Dec 2015 20:20:50 -0800
changeset 5205 eaff9ab86216
permissions -rw-r--r--
21637184 integrate GCC 4.9.3 in Solaris 21637193 enable CilkPlus support for SPARC in GCC 4.9.3

# Stefan Teleman <[email protected]>
# 1. Clearer cast not relying on array index -1.
# 2. Optimization based on initial std::string size and capacity.
# Internal patch. Not submitted upstream yet.
--- libstdc++-v3/include/bits/basic_string.h	2015-05-28 12:27:46.000000000 -0400
+++ libstdc++-v3/include/bits/basic_string.h	2015-09-14 01:16:05.666069507 -0400
@@ -131,6 +131,15 @@
       typedef std::reverse_iterator<iterator>		    reverse_iterator;
 
     private:
+      // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
+      struct _Alloc_hider : _Alloc
+      {
+	_Alloc_hider(_CharT* __dat, const _Alloc& __a) _GLIBCXX_NOEXCEPT
+	: _Alloc(__a), _M_p(__dat) { }
+
+	_CharT* _M_p; // The actual data.
+      };
+
       // _Rep: string representation
       //   Invariants:
       //   1. String really contains _M_length + 1 characters: due to 21.3.4
@@ -268,15 +277,6 @@
 	_M_clone(const _Alloc&, size_type __res = 0);
       };
 
-      // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
-      struct _Alloc_hider : _Alloc
-      {
-	_Alloc_hider(_CharT* __dat, const _Alloc& __a) _GLIBCXX_NOEXCEPT
-	: _Alloc(__a), _M_p(__dat) { }
-
-	_CharT* _M_p; // The actual data.
-      };
-
     public:
       // Data Members (public):
       // NB: This is an unsigned type, and thus represents the maximum
@@ -298,7 +298,10 @@
 
       _Rep*
       _M_rep() const _GLIBCXX_NOEXCEPT
-      { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
+      {
+        _Rep* __r = static_cast<_Rep*>(reinterpret_cast<void*>(_M_data()));
+        return --__r;
+      }
 
       // For the internal use we have functions similar to `begin'/`end'
       // but they do not call _M_leak.
--- libstdc++-v3/include/bits/basic_string.tcc	2014-01-02 17:30:10.000000000 -0500
+++ libstdc++-v3/include/bits/basic_string.tcc	2015-09-14 01:16:09.408163359 -0400
@@ -575,7 +575,8 @@
       // malloc implementations that allocate memory blocks rounded up
       // to a size which is a power of 2).
       const size_type __pagesize = 4096;
-      const size_type __malloc_header_size = 4 * sizeof(void*);
+      const size_type __min_capacity = 32;
+      const size_type __malloc_header_size = 8 * sizeof(void*);
 
       // The below implements an exponential growth policy, necessary to
       // meet amortized linear time requirements of the library: see
@@ -586,6 +587,9 @@
       if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
 	__capacity = 2 * __old_capacity;
 
+      if (__capacity < __min_capacity)
+        __capacity = __min_capacity;
+
       // NB: Need an array of char_type[__capacity], plus a terminating
       // null char_type() element, plus enough for the _Rep data structure.
       // Whew. Seemingly so needy, yet so elemental.