View | Details | Raw Unified | Return to bug 24196
Collapse All | Expand All

(-)libstdc++-v3-orig/include/bits/basic_string.h (-14 / +4 lines)
Lines 211-221 Link Here
211
	void
211
	void
212
	_M_dispose(const _Alloc& __a)
212
	_M_dispose(const _Alloc& __a)
213
	{
213
	{
214
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
214
	  if (__gnu_cxx::__exchange_and_add(&this->_M_refcount, -1) <= 0)
215
	  if (__builtin_expect(this != &_S_empty_rep(), false))
215
	    _M_destroy(__a);
216
#endif
217
	    if (__gnu_cxx::__exchange_and_add(&this->_M_refcount, -1) <= 0)
218
	      _M_destroy(__a);
219
	}  // XXX MT
216
	}  // XXX MT
220
217
221
	void
218
	void
Lines 224-233 Link Here
224
	_CharT*
221
	_CharT*
225
	_M_refcopy() throw()
222
	_M_refcopy() throw()
226
	{
223
	{
227
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
224
	  __gnu_cxx::__atomic_add(&this->_M_refcount, 1);
228
	  if (__builtin_expect(this != &_S_empty_rep(), false))
229
#endif
230
            __gnu_cxx::__atomic_add(&this->_M_refcount, 1);
231
	  return _M_refdata();
225
	  return _M_refdata();
232
	}  // XXX MT
226
	}  // XXX MT
233
227
Lines 1984-1994 Link Here
1984
  template<typename _CharT, typename _Traits, typename _Alloc>
1978
  template<typename _CharT, typename _Traits, typename _Alloc>
1985
    inline basic_string<_CharT, _Traits, _Alloc>::
1979
    inline basic_string<_CharT, _Traits, _Alloc>::
1986
    basic_string()
1980
    basic_string()
1987
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
1981
    : _M_dataplus(_S_empty_rep()._M_refcopy(), _Alloc()) { }
1988
    : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
1989
#else
1990
    : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
1991
#endif
1992
1982
1993
  // operator+
1983
  // operator+
1994
  /**
1984
  /**
(-)libstdc++-v3-orig/include/bits/basic_string.tcc (-17 / +6 lines)
Lines 88-97 Link Here
88
      _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
88
      _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
89
		   input_iterator_tag)
89
		   input_iterator_tag)
90
      {
90
      {
91
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
92
	if (__beg == __end && __a == _Alloc())
91
	if (__beg == __end && __a == _Alloc())
93
	  return _S_empty_rep()._M_refdata();
92
	  return _S_empty_rep()._M_refcopy();
94
#endif
93
95
	// Avoid reallocation for common case.
94
	// Avoid reallocation for common case.
96
	_CharT __buf[128];
95
	_CharT __buf[128];
97
	size_type __len = 0;
96
	size_type __len = 0;
Lines 136-145 Link Here
136
      _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
135
      _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
137
		   forward_iterator_tag)
136
		   forward_iterator_tag)
138
      {
137
      {
139
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
140
	if (__beg == __end && __a == _Alloc())
138
	if (__beg == __end && __a == _Alloc())
141
	  return _S_empty_rep()._M_refdata();
139
	  return _S_empty_rep()._M_refcopy();
142
#endif
140
143
	// NB: Not required, but considered best practice.
141
	// NB: Not required, but considered best practice.
144
	if (__builtin_expect(__is_null_pointer(__beg) && __beg != __end, 0))
142
	if (__builtin_expect(__is_null_pointer(__beg) && __beg != __end, 0))
145
	  __throw_logic_error(__N("basic_string::_S_construct NULL not valid"));
143
	  __throw_logic_error(__N("basic_string::_S_construct NULL not valid"));
Lines 165-174 Link Here
165
    basic_string<_CharT, _Traits, _Alloc>::
163
    basic_string<_CharT, _Traits, _Alloc>::
166
    _S_construct(size_type __n, _CharT __c, const _Alloc& __a)
164
    _S_construct(size_type __n, _CharT __c, const _Alloc& __a)
167
    {
165
    {
168
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
169
      if (__n == 0 && __a == _Alloc())
166
      if (__n == 0 && __a == _Alloc())
170
	return _S_empty_rep()._M_refdata();
167
	return _S_empty_rep()._M_refcopy();
171
#endif
168
172
      // Check for out_of_range and length_error exceptions.
169
      // Check for out_of_range and length_error exceptions.
173
      _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
170
      _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
174
      if (__n)
171
      if (__n)
Lines 362-371 Link Here
362
    basic_string<_CharT, _Traits, _Alloc>::_Rep::
359
    basic_string<_CharT, _Traits, _Alloc>::_Rep::
363
    _M_destroy(const _Alloc& __a) throw ()
360
    _M_destroy(const _Alloc& __a) throw ()
364
    {
361
    {
365
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
366
      if (this == &_S_empty_rep())
367
	return;
368
#endif
369
      const size_type __size = sizeof(_Rep_base) +
362
      const size_type __size = sizeof(_Rep_base) +
370
	                       (this->_M_capacity + 1) * sizeof(_CharT);
363
	                       (this->_M_capacity + 1) * sizeof(_CharT);
371
      _Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(this), __size);
364
      _Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(this), __size);
Lines 375-384 Link Here
375
    void
368
    void
376
    basic_string<_CharT, _Traits, _Alloc>::_M_leak_hard()
369
    basic_string<_CharT, _Traits, _Alloc>::_M_leak_hard()
377
    {
370
    {
378
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
379
      if (_M_rep() == &_S_empty_rep())
380
	return;
381
#endif
382
      if (_M_rep()->_M_is_shared())
371
      if (_M_rep()->_M_is_shared())
383
	_M_mutate(0, 0, 0);
372
	_M_mutate(0, 0, 0);
384
      _M_rep()->_M_set_leaked();
373
      _M_rep()->_M_set_leaked();

Return to bug 24196