epoc32/include/stdapis/stlportv5/stl/_rope.c
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
     1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_rope.c	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_rope.c	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -1,15 +1,14 @@
     1.4  /*
     1.5 - * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     1.6   * Copyright (c) 1996,1997
     1.7   * Silicon Graphics Computer Systems, Inc.
     1.8   *
     1.9 - * Copyright (c) 1999 
    1.10 + * Copyright (c) 1999
    1.11   * Boris Fomitchev
    1.12   *
    1.13   * This material is provided "as is", with absolutely no warranty expressed
    1.14   * or implied. Any use is at your own risk.
    1.15   *
    1.16 - * Permission to use or copy this software for any purpose is hereby granted 
    1.17 + * Permission to use or copy this software for any purpose is hereby granted
    1.18   * without fee, provided the above notices are retained on all copies.
    1.19   * Permission to modify the code and to distribute modified code is granted,
    1.20   * provided the above notices are retained, and a notice that the code was
    1.21 @@ -25,22 +24,24 @@
    1.22  // if necessary.  Assumes path_end[leaf_index] and leaf_pos are correct.
    1.23  // Results in a valid buf_ptr if the iterator can be legitimately
    1.24  // dereferenced.
    1.25 -# ifndef _STLP_ROPEIMPL_H
    1.26 -# define _STLP_ROPEIMPL_H
    1.27 +#ifndef _STLP_ROPEIMPL_H
    1.28 +#define _STLP_ROPEIMPL_H
    1.29  
    1.30  #ifndef _STLP_INTERNAL_ROPE_H
    1.31 -# include <stl/_rope.h>
    1.32 +#  include <stl/_rope.h>
    1.33  #endif
    1.34  
    1.35 -# ifndef _STLP_CSTDIO
    1.36 -#  include <cstdio>
    1.37 -# endif
    1.38 -
    1.39 -#ifndef _STLP_IOSTREAM
    1.40 -# include <iostream>
    1.41 +#ifndef _STLP_INTERNAL_CSTDIO
    1.42 +#  include <stl/_cstdio.h>
    1.43  #endif
    1.44  
    1.45 -# include <stl/_range_errors.h>
    1.46 +#if !defined (_STLP_USE_NO_IOSTREAMS)
    1.47 +#  ifndef _STLP_IOSTREAM
    1.48 +#    include <iostream>
    1.49 +#  endif
    1.50 +#endif
    1.51 +
    1.52 +#include <stl/_range_errors.h>
    1.53  
    1.54  _STLP_BEGIN_NAMESPACE
    1.55  
    1.56 @@ -56,255 +57,251 @@
    1.57    _M_root_rope(__r) { _RopeRep::_S_ref(this->_M_root); }
    1.58  
    1.59  template<class _CharT, class _Alloc>
    1.60 -_Rope_iterator<_CharT, _Alloc>::_Rope_iterator(rope<_CharT,_Alloc>& __r, size_t __pos): 
    1.61 -  _Rope_iterator_base<_CharT,_Alloc>(__r._M_tree_ptr._M_data, __pos), 
    1.62 +_Rope_iterator<_CharT, _Alloc>::_Rope_iterator(rope<_CharT,_Alloc>& __r, size_t __pos):
    1.63 +  _Rope_iterator_base<_CharT,_Alloc>(__r._M_tree_ptr._M_data, __pos),
    1.64    _M_root_rope(&__r) {
    1.65 +#if !defined (__DMC__)
    1.66    _RopeRep::_S_ref(this->_M_root); if (!(__r.empty()))_S_setcache(*this);
    1.67 +#else
    1.68 +  _Rope_iterator_base<_CharT, _Alloc>* __x = this;
    1.69 +  _RopeRep::_S_ref(this->_M_root); if (!(__r.empty()))_S_setcache(*__x);
    1.70 +#endif
    1.71  }
    1.72  
    1.73  template<class _CharT, class _Alloc>
    1.74 -void 
    1.75 -_Rope_RopeRep<_CharT, _Alloc>::_M_free_c_string()
    1.76 -{
    1.77 +void _Rope_RopeRep<_CharT, _Alloc>::_M_free_c_string() {
    1.78    _CharT* __cstr = _M_c_string;
    1.79    if (0 != __cstr) {
    1.80      size_t _p_size = _M_size._M_data + 1;
    1.81 -    _STLP_STD::_Destroy(__cstr, __cstr + _p_size);
    1.82 +    _STLP_STD::_Destroy_Range(__cstr, __cstr + _p_size);
    1.83      _M_size.deallocate(__cstr, _p_size);
    1.84    }
    1.85  }
    1.86  
    1.87 -
    1.88  // Set buf_start, buf_end, and buf_ptr appropriately, filling tmp_buf
    1.89  // if necessary.  Assumes _M_path_end[leaf_index] and leaf_pos are correct.
    1.90  // Results in a valid buf_ptr if the iterator can be legitimately
    1.91  // dereferenced.
    1.92  template <class _CharT, class _Alloc>
    1.93 -void _Rope_iterator_base<_CharT,_Alloc>::_S_setbuf( 
    1.94 -  _Rope_iterator_base<_CharT,_Alloc>& __x)
    1.95 -{
    1.96 -    const _RopeRep* __leaf = __x._M_path_end[__x._M_leaf_index];
    1.97 -    size_t __leaf_pos = __x._M_leaf_pos;
    1.98 -    size_t __pos = __x._M_current_pos;
    1.99 +void _Rope_iterator_base<_CharT,_Alloc>::_S_setbuf(
   1.100 +  _Rope_iterator_base<_CharT,_Alloc>& __x) {
   1.101 +  const _RopeRep* __leaf = __x._M_path_end._M_data[__x._M_leaf_index];
   1.102 +  size_t __leaf_pos = __x._M_leaf_pos;
   1.103 +  size_t __pos = __x._M_current_pos;
   1.104  
   1.105 -    switch(__leaf->_M_tag) {
   1.106 -	case _RopeRep::_S_leaf:
   1.107 -	    __x._M_buf_start = 
   1.108 -	      ((_Rope_RopeLeaf<_CharT,_Alloc>*)__leaf)->_M_data;
   1.109 -	    __x._M_buf_ptr = __x._M_buf_start + (__pos - __leaf_pos);
   1.110 -	    __x._M_buf_end = __x._M_buf_start + __leaf->_M_size._M_data;
   1.111 -	    break;
   1.112 -	case _RopeRep::_S_function:
   1.113 -	case _RopeRep::_S_substringfn:
   1.114 -	    {
   1.115 -		size_t __len = _S_iterator_buf_len;
   1.116 -		size_t __buf_start_pos = __leaf_pos;
   1.117 -		size_t __leaf_end = __leaf_pos + __leaf->_M_size._M_data;
   1.118 -		char_producer<_CharT>* __fn =
   1.119 -			((_Rope_RopeFunction<_CharT,_Alloc>*)__leaf)->_M_fn;
   1.120 +  switch(__leaf->_M_tag) {
   1.121 +  case _RopeRep::_S_leaf:
   1.122 +    typedef _Rope_RopeLeaf<_CharT, _Alloc> _RopeLeaf;
   1.123 +    __x._M_buf_start = __STATIC_CAST(const _RopeLeaf*, __leaf)->_M_data;
   1.124 +    __x._M_buf_ptr = __x._M_buf_start + (__pos - __leaf_pos);
   1.125 +    __x._M_buf_end = __x._M_buf_start + __leaf->_M_size._M_data;
   1.126 +    break;
   1.127 +  case _RopeRep::_S_function:
   1.128 +  case _RopeRep::_S_substringfn:
   1.129 +    {
   1.130 +      size_t __len = _S_iterator_buf_len;
   1.131 +      size_t __buf_start_pos = __leaf_pos;
   1.132 +      size_t __leaf_end = __leaf_pos + __leaf->_M_size._M_data;
   1.133 +      typedef _Rope_RopeFunction<_CharT, _Alloc> _RopeFunction;
   1.134 +      char_producer<_CharT>* __fn = __STATIC_CAST(const _RopeFunction*, __leaf)->_M_fn;
   1.135  
   1.136 -		if (__buf_start_pos + __len <= __pos) {
   1.137 -		    __buf_start_pos = __pos - __len/4;
   1.138 -		    if (__buf_start_pos + __len > __leaf_end) {
   1.139 -			__buf_start_pos = __leaf_end - __len;
   1.140 -		    }
   1.141 -		}
   1.142 -		if (__buf_start_pos + __len > __leaf_end) {
   1.143 -		    __len = __leaf_end - __buf_start_pos;
   1.144 -		}
   1.145 -		(*__fn)(__buf_start_pos - __leaf_pos, __len, __x._M_tmp_buf);
   1.146 -		__x._M_buf_ptr = __x._M_tmp_buf + (__pos - __buf_start_pos);
   1.147 -		__x._M_buf_start = __x._M_tmp_buf;
   1.148 -		__x._M_buf_end = __x._M_tmp_buf + __len;
   1.149 -	    }
   1.150 -	    break;
   1.151 -	default:
   1.152 +      if (__buf_start_pos + __len <= __pos) {
   1.153 +        __buf_start_pos = __pos - __len/4;
   1.154 +        if (__buf_start_pos + __len > __leaf_end) {
   1.155 +          __buf_start_pos = __leaf_end - __len;
   1.156 +        }
   1.157 +      }
   1.158 +      if (__buf_start_pos + __len > __leaf_end) {
   1.159 +        __len = __leaf_end - __buf_start_pos;
   1.160 +      }
   1.161 +      (*__fn)(__buf_start_pos - __leaf_pos, __len, __x._M_tmp_buf._M_data);
   1.162 +      __x._M_buf_ptr = __x._M_tmp_buf._M_data + (__pos - __buf_start_pos);
   1.163 +      __x._M_buf_start = __x._M_tmp_buf._M_data;
   1.164 +      __x._M_buf_end = __x._M_tmp_buf._M_data + __len;
   1.165 +    }
   1.166 +    break;
   1.167 +  default:
   1.168        _STLP_ASSERT(0)
   1.169 -        ;
   1.170 -    }
   1.171 +      ;
   1.172 +  }
   1.173  }
   1.174  
   1.175 -// Set path and buffer inside a rope iterator.  We assume that 
   1.176 +// Set path and buffer inside a rope iterator.  We assume that
   1.177  // pos and root are already set.
   1.178  template <class _CharT, class _Alloc>
   1.179 -void _Rope_iterator_base<_CharT,_Alloc>::_S_setcache
   1.180 -(_Rope_iterator_base<_CharT,_Alloc>& __x)
   1.181 -{
   1.182 -    const _RopeRep* __path[_RopeRep::_S_max_rope_depth+1];
   1.183 -    const _RopeRep* __curr_rope;
   1.184 -    int __curr_depth = -1;  /* index into path    */
   1.185 -    size_t __curr_start_pos = 0;
   1.186 -    size_t __pos = __x._M_current_pos;
   1.187 -    unsigned char __dirns = 0; // Bit vector marking right turns in the path
   1.188 +void _Rope_iterator_base<_CharT,_Alloc>::_S_setcache(
   1.189 +  _Rope_iterator_base<_CharT,_Alloc>& __x) {
   1.190 +  const _RopeRep* __path[_RopeRep::_S_max_rope_depth+1];
   1.191 +  const _RopeRep* __curr_rope;
   1.192 +  int __curr_depth = -1;  /* index into path    */
   1.193 +  size_t __curr_start_pos = 0;
   1.194 +  size_t __pos = __x._M_current_pos;
   1.195 +  unsigned char __dirns = 0; // Bit vector marking right turns in the path
   1.196  
   1.197 -    _STLP_ASSERT(__pos <= __x._M_root->_M_size._M_data)
   1.198 -    if (__pos >= __x._M_root->_M_size._M_data) {
   1.199 -	__x._M_buf_ptr = 0;
   1.200 -	return;
   1.201 +  _STLP_ASSERT(__pos <= __x._M_root->_M_size._M_data)
   1.202 +  if (__pos >= __x._M_root->_M_size._M_data) {
   1.203 +    __x._M_buf_ptr = 0;
   1.204 +    return;
   1.205 +  }
   1.206 +  __curr_rope = __x._M_root;
   1.207 +  if (0 != __curr_rope->_M_c_string) {
   1.208 +    /* Treat the root as a leaf. */
   1.209 +    __x._M_buf_start = __curr_rope->_M_c_string;
   1.210 +    __x._M_buf_end = __curr_rope->_M_c_string + __curr_rope->_M_size._M_data;
   1.211 +    __x._M_buf_ptr = __curr_rope->_M_c_string + __pos;
   1.212 +    __x._M_path_end._M_data[0] = __curr_rope;
   1.213 +    __x._M_leaf_index = 0;
   1.214 +    __x._M_leaf_pos = 0;
   1.215 +    return;
   1.216 +  }
   1.217 +  for(;;) {
   1.218 +    ++__curr_depth;
   1.219 +    _STLP_ASSERT(__curr_depth <= _RopeRep::_S_max_rope_depth)
   1.220 +    __path[__curr_depth] = __curr_rope;
   1.221 +    switch(__curr_rope->_M_tag) {
   1.222 +    case _RopeRep::_S_leaf:
   1.223 +    case _RopeRep::_S_function:
   1.224 +    case _RopeRep::_S_substringfn:
   1.225 +      __x._M_leaf_pos = __curr_start_pos;
   1.226 +      goto done;
   1.227 +    case _RopeRep::_S_concat:
   1.228 +      {
   1.229 +        const _RopeConcat* __c = __STATIC_CAST(const _RopeConcat*, __curr_rope);
   1.230 +        _RopeRep* __left = __c->_M_left;
   1.231 +        size_t __left_len = __left->_M_size._M_data;
   1.232 +
   1.233 +        __dirns <<= 1;
   1.234 +        if (__pos >= __curr_start_pos + __left_len) {
   1.235 +          __dirns |= 1;
   1.236 +          __curr_rope = __c->_M_right;
   1.237 +          __curr_start_pos += __left_len;
   1.238 +        } else {
   1.239 +          __curr_rope = __left;
   1.240 +        }
   1.241 +      }
   1.242 +      break;
   1.243      }
   1.244 -    __curr_rope = __x._M_root;
   1.245 -    if (0 != __curr_rope->_M_c_string) {
   1.246 -	/* Treat the root as a leaf. */
   1.247 -	__x._M_buf_start = __curr_rope->_M_c_string;
   1.248 -	__x._M_buf_end = __curr_rope->_M_c_string + __curr_rope->_M_size._M_data;
   1.249 -	__x._M_buf_ptr = __curr_rope->_M_c_string + __pos;
   1.250 -	__x._M_path_end[0] = __curr_rope;
   1.251 -	__x._M_leaf_index = 0;
   1.252 -	__x._M_leaf_pos = 0;
   1.253 -	return;
   1.254 +  }
   1.255 +done:
   1.256 +    // Copy last section of path into _M_path_end.
   1.257 +  {
   1.258 +    int __i = -1;
   1.259 +    int __j = __curr_depth + 1 - _S_path_cache_len;
   1.260 +
   1.261 +    if (__j < 0) __j = 0;
   1.262 +    while (__j <= __curr_depth) {
   1.263 +      __x._M_path_end._M_data[++__i] = __path[__j++];
   1.264      }
   1.265 -    for(;;) {
   1.266 -	++__curr_depth;
   1.267 -	_STLP_ASSERT(__curr_depth <= _RopeRep::_S_max_rope_depth)
   1.268 -	__path[__curr_depth] = __curr_rope;
   1.269 -	switch(__curr_rope->_M_tag) {
   1.270 -	  case _RopeRep::_S_leaf:
   1.271 -	  case _RopeRep::_S_function:
   1.272 -	  case _RopeRep::_S_substringfn:
   1.273 -	    __x._M_leaf_pos = __curr_start_pos;
   1.274 -	    goto done;
   1.275 -	  case _RopeRep::_S_concat:
   1.276 -	    {
   1.277 -		_Rope_RopeConcatenation<_CharT,_Alloc>* __c =
   1.278 -			(_Rope_RopeConcatenation<_CharT,_Alloc>*)__curr_rope;
   1.279 -		_RopeRep* __left = __c->_M_left;
   1.280 -		size_t __left_len = __left->_M_size._M_data;
   1.281 -		
   1.282 -		__dirns <<= 1;
   1.283 -		if (__pos >= __curr_start_pos + __left_len) {
   1.284 -		    __dirns |= 1;
   1.285 -		    __curr_rope = __c->_M_right;
   1.286 -		    __curr_start_pos += __left_len;
   1.287 -		} else {
   1.288 -		    __curr_rope = __left;
   1.289 -		}
   1.290 -	    }
   1.291 -	    break;
   1.292 -	}
   1.293 -    }
   1.294 -  done:
   1.295 -    // Copy last section of path into _M_path_end.
   1.296 -      {
   1.297 -	int __i = -1;
   1.298 -	int __j = __curr_depth + 1 - _S_path_cache_len;
   1.299 -
   1.300 -	if (__j < 0) __j = 0;
   1.301 -	while (__j <= __curr_depth) {
   1.302 -	    __x._M_path_end[++__i] = __path[__j++];
   1.303 -	}
   1.304 -	__x._M_leaf_index = __i;
   1.305 -      }
   1.306 -      __x._M_path_directions = __dirns;
   1.307 -      _S_setbuf(__x);
   1.308 +    __x._M_leaf_index = __i;
   1.309 +  }
   1.310 +  __x._M_path_directions = __dirns;
   1.311 +  _S_setbuf(__x);
   1.312  }
   1.313  
   1.314  // Specialized version of the above.  Assumes that
   1.315  // the path cache is valid for the previous position.
   1.316  template <class _CharT, class _Alloc>
   1.317 -void _Rope_iterator_base<_CharT,_Alloc>::_S_setcache_for_incr
   1.318 -(_Rope_iterator_base<_CharT,_Alloc>& __x)
   1.319 -{
   1.320 -    int __current_index = __x._M_leaf_index;
   1.321 -    const _RopeRep* __current_node = __x._M_path_end[__current_index];
   1.322 -    size_t __len = __current_node->_M_size._M_data;
   1.323 -    size_t __node_start_pos = __x._M_leaf_pos;
   1.324 -    unsigned char __dirns = __x._M_path_directions;
   1.325 -    _Rope_RopeConcatenation<_CharT,_Alloc>* __c;
   1.326 +void _Rope_iterator_base<_CharT,_Alloc>::_S_setcache_for_incr(
   1.327 +_Rope_iterator_base<_CharT,_Alloc>& __x) {
   1.328 +  int __current_index = __x._M_leaf_index;
   1.329 +  const _RopeRep* __current_node = __x._M_path_end._M_data[__current_index];
   1.330 +  size_t __len = __current_node->_M_size._M_data;
   1.331 +  size_t __node_start_pos = __x._M_leaf_pos;
   1.332 +  unsigned char __dirns = __x._M_path_directions;
   1.333 +  const _RopeConcat* __c;
   1.334  
   1.335 -    _STLP_ASSERT(__x._M_current_pos <= __x._M_root->_M_size._M_data)
   1.336 -    if (__x._M_current_pos - __node_start_pos < __len) {
   1.337 -	/* More stuff in this leaf, we just didn't cache it. */
   1.338 -	_S_setbuf(__x);
   1.339 -	return;
   1.340 +  _STLP_ASSERT(__x._M_current_pos <= __x._M_root->_M_size._M_data)
   1.341 +  if (__x._M_current_pos - __node_start_pos < __len) {
   1.342 +    /* More stuff in this leaf, we just didn't cache it. */
   1.343 +    _S_setbuf(__x);
   1.344 +    return;
   1.345 +  }
   1.346 +  _STLP_ASSERT(__node_start_pos + __len == __x._M_current_pos)
   1.347 +    //  node_start_pos is starting position of last_node.
   1.348 +  while (--__current_index >= 0) {
   1.349 +    if (!(__dirns & 1) /* Path turned left */)
   1.350 +      break;
   1.351 +    __current_node = __x._M_path_end._M_data[__current_index];
   1.352 +    __c = __STATIC_CAST(const _RopeConcat*, __current_node);
   1.353 +    // Otherwise we were in the right child.  Thus we should pop
   1.354 +    // the concatenation node.
   1.355 +    __node_start_pos -= __c->_M_left->_M_size._M_data;
   1.356 +    __dirns >>= 1;
   1.357 +  }
   1.358 +  if (__current_index < 0) {
   1.359 +    // We underflowed the cache. Punt.
   1.360 +    _S_setcache(__x);
   1.361 +    return;
   1.362 +  }
   1.363 +  __current_node = __x._M_path_end._M_data[__current_index];
   1.364 +  __c = __STATIC_CAST(const _RopeConcat*, __current_node);
   1.365 +  // current_node is a concatenation node.  We are positioned on the first
   1.366 +  // character in its right child.
   1.367 +  // node_start_pos is starting position of current_node.
   1.368 +  __node_start_pos += __c->_M_left->_M_size._M_data;
   1.369 +  __current_node = __c->_M_right;
   1.370 +  __x._M_path_end._M_data[++__current_index] = __current_node;
   1.371 +  __dirns |= 1;
   1.372 +  while (_RopeRep::_S_concat == __current_node->_M_tag) {
   1.373 +    ++__current_index;
   1.374 +    if (_S_path_cache_len == __current_index) {
   1.375 +      int __i;
   1.376 +      for (__i = 0; __i < _S_path_cache_len-1; ++__i) {
   1.377 +        __x._M_path_end._M_data[__i] = __x._M_path_end._M_data[__i+1];
   1.378 +      }
   1.379 +      --__current_index;
   1.380      }
   1.381 -    _STLP_ASSERT(__node_start_pos + __len == __x._M_current_pos)
   1.382 -    //  node_start_pos is starting position of last_node.
   1.383 -    while (--__current_index >= 0) {
   1.384 -	if (!(__dirns & 1) /* Path turned left */) 
   1.385 -	  break;
   1.386 -	__current_node = __x._M_path_end[__current_index];
   1.387 -	__c = (_Rope_RopeConcatenation<_CharT,_Alloc>*)__current_node;
   1.388 -	// Otherwise we were in the right child.  Thus we should pop
   1.389 -	// the concatenation node.
   1.390 -	__node_start_pos -= __c->_M_left->_M_size._M_data;
   1.391 -	__dirns >>= 1;
   1.392 -    }
   1.393 -    if (__current_index < 0) {
   1.394 -	// We underflowed the cache. Punt.
   1.395 -	_S_setcache(__x);
   1.396 -	return;
   1.397 -    }
   1.398 -    __current_node = __x._M_path_end[__current_index];
   1.399 -    __c = (_Rope_RopeConcatenation<_CharT,_Alloc>*)__current_node;
   1.400 -    // current_node is a concatenation node.  We are positioned on the first
   1.401 -    // character in its right child.
   1.402 -    // node_start_pos is starting position of current_node.
   1.403 -    __node_start_pos += __c->_M_left->_M_size._M_data;
   1.404 -    __current_node = __c->_M_right;
   1.405 -    __x._M_path_end[++__current_index] = __current_node;
   1.406 -    __dirns |= 1;
   1.407 -    while (_RopeRep::_S_concat == __current_node->_M_tag) {
   1.408 -	++__current_index;
   1.409 -	if (_S_path_cache_len == __current_index) {
   1.410 -	    int __i;
   1.411 -	    for (__i = 0; __i < _S_path_cache_len-1; __i++) {
   1.412 -		__x._M_path_end[__i] = __x._M_path_end[__i+1];
   1.413 -	    }
   1.414 -	    --__current_index;
   1.415 -	}
   1.416 -	__current_node =
   1.417 -	    ((_Rope_RopeConcatenation<_CharT,_Alloc>*)__current_node)->_M_left;
   1.418 -	__x._M_path_end[__current_index] = __current_node;
   1.419 -	__dirns <<= 1;
   1.420 -	// node_start_pos is unchanged.
   1.421 -    }
   1.422 -    __x._M_leaf_index = __current_index;
   1.423 -    __x._M_leaf_pos = __node_start_pos;
   1.424 -    __x._M_path_directions = __dirns;
   1.425 -    _S_setbuf(__x);
   1.426 +    __current_node = __STATIC_CAST(const _RopeConcat*, __current_node)->_M_left;
   1.427 +    __x._M_path_end._M_data[__current_index] = __current_node;
   1.428 +    __dirns <<= 1;
   1.429 +    // node_start_pos is unchanged.
   1.430 +  }
   1.431 +  __x._M_leaf_index = __current_index;
   1.432 +  __x._M_leaf_pos = __node_start_pos;
   1.433 +  __x._M_path_directions = __dirns;
   1.434 +  _S_setbuf(__x);
   1.435  }
   1.436  
   1.437  template <class _CharT, class _Alloc>
   1.438  void _Rope_iterator_base<_CharT,_Alloc>::_M_incr(size_t __n) {
   1.439 -    _M_current_pos += __n;
   1.440 -    if (0 != _M_buf_ptr) {
   1.441 -        size_t __chars_left = _M_buf_end - _M_buf_ptr;
   1.442 -        if (__chars_left > __n) {
   1.443 -            _M_buf_ptr += __n;
   1.444 -        } else if (__chars_left == __n) {
   1.445 -            _M_buf_ptr += __n;
   1.446 -            _S_setcache_for_incr(*this);
   1.447 -        } else {
   1.448 -            _M_buf_ptr = 0;
   1.449 -        }
   1.450 +  _M_current_pos += __n;
   1.451 +  if (0 != _M_buf_ptr) {
   1.452 +    size_t __chars_left = _M_buf_end - _M_buf_ptr;
   1.453 +    if (__chars_left > __n) {
   1.454 +      _M_buf_ptr += __n;
   1.455 +    } else if (__chars_left == __n) {
   1.456 +      _M_buf_ptr += __n;
   1.457 +      _S_setcache_for_incr(*this);
   1.458 +    } else {
   1.459 +      _M_buf_ptr = 0;
   1.460      }
   1.461 +  }
   1.462  }
   1.463  
   1.464  template <class _CharT, class _Alloc>
   1.465  void _Rope_iterator_base<_CharT,_Alloc>::_M_decr(size_t __n) {
   1.466 -    if (0 != _M_buf_ptr) {
   1.467 -        size_t __chars_left = _M_buf_ptr - _M_buf_start;
   1.468 -        if (__chars_left >= __n) {
   1.469 -            _M_buf_ptr -= __n;
   1.470 -        } else {
   1.471 -            _M_buf_ptr = 0;
   1.472 -        }
   1.473 +  if (0 != _M_buf_ptr) {
   1.474 +    size_t __chars_left = _M_buf_ptr - _M_buf_start;
   1.475 +    if (__chars_left >= __n) {
   1.476 +      _M_buf_ptr -= __n;
   1.477 +    } else {
   1.478 +      _M_buf_ptr = 0;
   1.479      }
   1.480 -    _M_current_pos -= __n;
   1.481 +  }
   1.482 +  _M_current_pos -= __n;
   1.483  }
   1.484  
   1.485  template <class _CharT, class _Alloc>
   1.486  void _Rope_iterator<_CharT,_Alloc>::_M_check() {
   1.487 -    if (_M_root_rope->_M_tree_ptr._M_data != this->_M_root) {
   1.488 -        // _Rope was modified.  Get things fixed up.
   1.489 -        _RopeRep::_S_unref(this->_M_root);
   1.490 -        this->_M_root = _M_root_rope->_M_tree_ptr._M_data;
   1.491 -        _RopeRep::_S_ref(this->_M_root);
   1.492 -        this->_M_buf_ptr = 0;
   1.493 -    }
   1.494 +  if (_M_root_rope->_M_tree_ptr._M_data != this->_M_root) {
   1.495 +    // _Rope was modified.  Get things fixed up.
   1.496 +    _RopeRep::_S_unref(this->_M_root);
   1.497 +    this->_M_root = _M_root_rope->_M_tree_ptr._M_data;
   1.498 +    _RopeRep::_S_ref(this->_M_root);
   1.499 +    this->_M_buf_ptr = 0;
   1.500 +  }
   1.501  }
   1.502  
   1.503 -# ifndef _GC
   1.504  //  There are several reasons for not doing this with virtual destructors
   1.505  //  and a class specific delete operator:
   1.506  //  - A class specific delete operator can't easily get access to
   1.507 @@ -312,47 +309,46 @@
   1.508  //  - Any virtual function would need a 4 or byte vtable pointer;
   1.509  //    this only requires a one byte tag per object.
   1.510  template <class _CharT, class _Alloc>
   1.511 -void _Rope_RopeRep<_CharT,_Alloc>::_M_free_tree()
   1.512 -{
   1.513 -    switch(_M_tag) {
   1.514 -	case _S_leaf:
   1.515 -	    {
   1.516 -	      typedef _Rope_RopeLeaf<_CharT,_Alloc> _Rope_RopeLeaf_T;
   1.517 -          _Rope_RopeLeaf_T* __l = (_Rope_RopeLeaf_T*)this;
   1.518 -          _STLP_STD::_Destroy(__l); // ->_Rope_RopeLeaf<_CharT,_Alloc>::~_Rope_RopeLeaf();
   1.519 -	      _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_size, _Rope_RopeLeaf_T).deallocate(__l, 1);
   1.520 -	        break;
   1.521 -	    }
   1.522 -	case _S_concat:
   1.523 -	    {
   1.524 -               typedef _Rope_RopeConcatenation<_CharT,_Alloc> _Rope_RopeConcatenation_T;
   1.525 -               _Rope_RopeConcatenation_T* __c  = (_Rope_RopeConcatenation_T*)this;
   1.526 -               _STLP_STD::_Destroy(__c);
   1.527 -               _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_size, 
   1.528 -                               _Rope_RopeConcatenation_T).deallocate(__c, 1);
   1.529 -	        break;
   1.530 -	    }
   1.531 -	case _S_function:
   1.532 -	    {
   1.533 -            typedef _Rope_RopeFunction<_CharT,_Alloc> _Rope_RopeFunctionT;
   1.534 -              _Rope_RopeFunctionT* __f = (_Rope_RopeFunctionT*)this;
   1.535 -              _STLP_STD::_Destroy(__f);
   1.536 -              _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_size, 
   1.537 -                                 _Rope_RopeFunctionT).deallocate(__f, 1);
   1.538 -	        break;
   1.539 -	    }
   1.540 -	case _S_substringfn:
   1.541 -	    {
   1.542 -            typedef _Rope_RopeSubstring<_CharT,_Alloc> _Rope_RopeSubstring_T;
   1.543 -              _Rope_RopeSubstring_T* __ss = (_Rope_RopeSubstring_T*)this;
   1.544 -              _STLP_STD::_Destroy(__ss);
   1.545 -              _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_size, 
   1.546 -                              _Rope_RopeSubstring_T).deallocate(__ss, 1);
   1.547 -		break;
   1.548 -	    }
   1.549 +void _Rope_RopeRep<_CharT,_Alloc>::_M_free_tree() {
   1.550 +  switch (_M_tag) {
   1.551 +  case _S_leaf:
   1.552 +    {
   1.553 +      typedef _Rope_RopeLeaf<_CharT, _Alloc> _RopeLeaf;
   1.554 +      _RopeLeaf* __l = __STATIC_CAST(_RopeLeaf*, this);
   1.555 +      _STLP_STD::_Destroy(__l); // ->_Rope_RopeLeaf<_CharT,_Alloc>::~_Rope_RopeLeaf();
   1.556 +      _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_size,
   1.557 +                             _RopeLeaf).deallocate(__l, 1);
   1.558 +      break;
   1.559      }
   1.560 +  case _S_concat:
   1.561 +    {
   1.562 +      typedef _Rope_RopeConcatenation<_CharT, _Alloc> _RopeConcatenation;
   1.563 +      _RopeConcatenation* __c  = __STATIC_CAST(_RopeConcatenation*, this);
   1.564 +      _STLP_STD::_Destroy(__c);
   1.565 +      _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_size,
   1.566 +                             _RopeConcatenation).deallocate(__c, 1);
   1.567 +      break;
   1.568 +    }
   1.569 +  case _S_function:
   1.570 +    {
   1.571 +      typedef _Rope_RopeFunction<_CharT, _Alloc> _RopeFunction;
   1.572 +      _RopeFunction* __f = __STATIC_CAST(_RopeFunction*, this);
   1.573 +      _STLP_STD::_Destroy(__f);
   1.574 +      _STLP_CREATE_ALLOCATOR(allocator_type, (const allocator_type&)_M_size,
   1.575 +                             _RopeFunction).deallocate(__f, 1);
   1.576 +      break;
   1.577 +    }
   1.578 +  case _S_substringfn:
   1.579 +    {
   1.580 +      typedef _Rope_RopeSubstring<_CharT, _Alloc> _RopeSubstring;
   1.581 +      _RopeSubstring* __rss = __STATIC_CAST(_RopeSubstring*, this);
   1.582 +      _STLP_STD::_Destroy(__rss);
   1.583 +      _STLP_CREATE_ALLOCATOR(allocator_type, (const allocator_type&)_M_size,
   1.584 +                             _RopeSubstring).deallocate(__rss, 1);
   1.585 +      break;
   1.586 +    }
   1.587 +  }
   1.588  }
   1.589 -#endif
   1.590  
   1.591  # if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
   1.592  #   define __RopeLeaf__ _Rope_RopeLeaf<_CharT,_Alloc>
   1.593 @@ -365,742 +361,649 @@
   1.594  #   define __RopeRep__ _STLP_TYPENAME_ON_RETURN_TYPE rope<_CharT,_Alloc>::_RopeRep
   1.595  # endif
   1.596  
   1.597 +template <class _CharT, class _Alloc>
   1.598 +void rope<_CharT, _Alloc>::_M_throw_out_of_range() const {
   1.599 +  __stl_throw_out_of_range("rope");
   1.600 +}
   1.601 +
   1.602  // Concatenate a C string onto a leaf rope by copying the rope data.
   1.603  // Used for short ropes.
   1.604  template <class _CharT, class _Alloc>
   1.605  __RopeLeaf__*
   1.606 -rope<_CharT,_Alloc>::_S_leaf_concat_char_iter
   1.607 -		(_RopeLeaf* __r, const _CharT* __iter, size_t __len)
   1.608 -{
   1.609 -    size_t __old_len = __r->_M_size._M_data;
   1.610 -    _CharT* __new_data = __r->_M_size.allocate(_S_rounded_up_size(__old_len + __len));
   1.611 -    _RopeLeaf* __result;
   1.612 -    
   1.613 -    uninitialized_copy_n(__r->_M_data, __old_len, __new_data);
   1.614 -    uninitialized_copy_n(__iter, __len, __new_data + __old_len);
   1.615 -    _S_cond_store_eos(__new_data[__old_len + __len]);
   1.616 -    _STLP_TRY {
   1.617 -	__result = _S_new_RopeLeaf(__new_data, __old_len + __len,
   1.618 -				   __r->get_allocator());
   1.619 -    }
   1.620 -    _STLP_UNWIND(_RopeRep::_S_free_string(__new_data, __old_len + __len,
   1.621 -					     __r->get_allocator()));
   1.622 -    return __result;
   1.623 +rope<_CharT,_Alloc>::_S_leaf_concat_char_iter (
   1.624 +  _RopeLeaf* __r, const _CharT* __iter, size_t __len) {
   1.625 +  size_t __old_len = __r->_M_size._M_data;
   1.626 +  _CharT* __new_data = __r->_M_size.allocate(_S_rounded_up_size(__old_len + __len));
   1.627 +  _RopeLeaf* __result;
   1.628 +
   1.629 +  _STLP_PRIV __ucopy_n(__r->_M_data, __old_len, __new_data);
   1.630 +  _STLP_PRIV __ucopy_n(__iter, __len, __new_data + __old_len);
   1.631 +  _S_construct_null(__new_data + __old_len + __len);
   1.632 +  _STLP_TRY {
   1.633 +    __result = _S_new_RopeLeaf(__new_data, __old_len + __len, __r->get_allocator());
   1.634 +  }
   1.635 +  _STLP_UNWIND(_RopeRep::_S_free_string(__new_data, __old_len + __len,
   1.636 +                                        __r->get_allocator()))
   1.637 +  return __result;
   1.638  }
   1.639  
   1.640 -#ifndef __GC
   1.641 +template <class _CharT, class _Alloc>
   1.642 +void _Terminate_RopeLeaf(_Rope_RopeLeaf<_CharT,_Alloc> *__r,
   1.643 +                         size_t __size, const __true_type& /*basic char type*/) {
   1.644 +  _S_construct_null(__r->_M_data + __size);
   1.645 +  _STLP_ASSERT(__r->_M_c_string == __r->_M_data)
   1.646 +}
   1.647 +
   1.648 +template <class _CharT, class _Alloc>
   1.649 +void _Terminate_RopeLeaf(_Rope_RopeLeaf<_CharT,_Alloc> *__r,
   1.650 +                         size_t, const __false_type& /*basic char type*/) {
   1.651 +  if (__r->_M_c_string != __r->_M_data && 0 != __r->_M_c_string) {
   1.652 +    __r->_M_free_c_string();
   1.653 +    __r->_M_c_string = 0;
   1.654 +  }
   1.655 +}
   1.656 +
   1.657  // As above, but it's OK to clobber original if refcount is 1
   1.658  template <class _CharT, class _Alloc>
   1.659  __RopeLeaf__*
   1.660 -rope<_CharT,_Alloc>::_S_destr_leaf_concat_char_iter
   1.661 -		(_RopeLeaf* __r, const _CharT* __iter, size_t __len)
   1.662 -{
   1.663 -    _STLP_ASSERT(__r->_M_ref_count >= 1)
   1.664 -    if (__r->_M_ref_count > 1)
   1.665 -      return _S_leaf_concat_char_iter(__r, __iter, __len);
   1.666 -    size_t __old_len = __r->_M_size._M_data;
   1.667 -    if (_S_allocated_capacity(__old_len) >= __old_len + __len) {
   1.668 -	// The space has been partially initialized for the standard
   1.669 -	// character types.  But that doesn't matter for those types.
   1.670 -	uninitialized_copy_n(__iter, __len, __r->_M_data + __old_len);
   1.671 -	if (_S_is_basic_char_type((_CharT*)0)) {
   1.672 -	    _S_cond_store_eos(__r->_M_data[__old_len + __len]);
   1.673 -	    _STLP_ASSERT(__r->_M_c_string == __r->_M_data)
   1.674 -	} else if (__r->_M_c_string != __r->_M_data && 0 != __r->_M_c_string) {
   1.675 -	    __r->_M_free_c_string();
   1.676 -	    __r->_M_c_string = 0;
   1.677 -	}
   1.678 -	__r->_M_size._M_data = __old_len + __len;
   1.679 -	_STLP_ASSERT(__r->_M_ref_count == 1)
   1.680 -	__r->_M_ref_count = 2;
   1.681 -	return __r;
   1.682 -    } else {
   1.683 -	_RopeLeaf* __result = _S_leaf_concat_char_iter(__r, __iter, __len);
   1.684 -	_STLP_ASSERT(__result->_M_ref_count == 1)
   1.685 -	return __result;
   1.686 -    }
   1.687 +rope<_CharT,_Alloc>::_S_destr_leaf_concat_char_iter (_RopeLeaf* __r, const _CharT* __iter, size_t __len) {
   1.688 +  //_STLP_ASSERT(__r->_M_ref_count >= 1)
   1.689 +  if ( /* __r->_M_ref_count > 1 */  __r->_M_incr() > 2 ) { // - ptr
   1.690 +    __r->_M_decr(); // - ptr
   1.691 +    return _S_leaf_concat_char_iter(__r, __iter, __len);
   1.692 +  }
   1.693 +  __r->_M_decr(); // - ptr, __r->_M_ref_count == 1 or 0
   1.694 +  size_t __old_len = __r->_M_size._M_data;
   1.695 +  if (_S_rounded_up_size(__old_len) == _S_rounded_up_size(__old_len + __len)) {
   1.696 +    // The space has been partially initialized for the standard
   1.697 +    // character types.  But that doesn't matter for those types.
   1.698 +    _STLP_PRIV __ucopy_n(__iter, __len, __r->_M_data + __old_len);
   1.699 +    _Terminate_RopeLeaf(__r, __old_len + __len, _IsBasicCharType());
   1.700 +    __r->_M_size._M_data = __old_len + __len;
   1.701 +    // _STLP_ASSERT(__r->_M_ref_count == 1)
   1.702 +    // __r->_M_ref_count = 2;
   1.703 +    __r->_M_incr(); // i.e.  __r->_M_ref_count = 2
   1.704 +    return __r;
   1.705 +  } else {
   1.706 +    _RopeLeaf* __result = _S_leaf_concat_char_iter(__r, __iter, __len);
   1.707 +    //_STLP_ASSERT(__result->_M_ref_count == 1)
   1.708 +    return __result;
   1.709 +  }
   1.710  }
   1.711 -#endif
   1.712  
   1.713  // Assumes left and right are not 0.
   1.714  // Does not increment (nor decrement on exception) child reference counts.
   1.715  // Result has ref count 1.
   1.716  template <class _CharT, class _Alloc>
   1.717  __RopeRep__*
   1.718 -rope<_CharT,_Alloc>::_S_tree_concat (_RopeRep* __left, _RopeRep* __right)
   1.719 -{
   1.720 -    _RopeConcatenation* __result =
   1.721 -      _S_new_RopeConcatenation(__left, __right, __left->get_allocator());
   1.722 -    size_t __depth = __result->_M_depth;
   1.723 -    
   1.724 -    _STLP_ASSERT(__left->get_allocator() == __right->get_allocator())
   1.725 -    if (__depth > 20 && (__result->_M_size._M_data < 1000 ||
   1.726 -			 __depth > _RopeRep::_S_max_rope_depth)) {
   1.727 -        _RopeRep* __balanced;
   1.728 -      
   1.729 -	_STLP_TRY {
   1.730 -	   __balanced = _S_balance(__result);
   1.731 -#          ifndef __GC
   1.732 -	     if (__result != __balanced) {
   1.733 -		_STLP_ASSERT(1 == __result->_M_ref_count
   1.734 -			     && 1 == __balanced->_M_ref_count)
   1.735 -	     }
   1.736 -#          endif
   1.737 -	   __result->_M_unref_nonnil();
   1.738 -        }
   1.739 -      _STLP_UNWIND((_STLP_CREATE_ALLOCATOR(allocator_type,(allocator_type&)__left->_M_size,
   1.740 -                                    _RopeConcatenation).deallocate(__result,1)));
   1.741 -		// In case of exception, we need to deallocate
   1.742 -		// otherwise dangling result node.  But caller
   1.743 -		// still owns its children.  Thus unref is
   1.744 -		// inappropriate.
   1.745 -	return __balanced;
   1.746 -    } else {
   1.747 -	return __result;
   1.748 +rope<_CharT,_Alloc>::_S_tree_concat (_RopeRep* __left, _RopeRep* __right) {
   1.749 +  _RopeConcatenation* __result =
   1.750 +    _S_new_RopeConcatenation(__left, __right, __left->get_allocator());
   1.751 +  size_t __depth = __result->_M_depth;
   1.752 +
   1.753 +  _STLP_ASSERT(__left->get_allocator() == __right->get_allocator())
   1.754 +  if (__depth > 20 && (__result->_M_size._M_data < 1000 ||
   1.755 +      __depth > _RopeRep::_S_max_rope_depth)) {
   1.756 +    _RopeRep* __balanced;
   1.757 +
   1.758 +    _STLP_TRY {
   1.759 +      __balanced = _S_balance(__result);
   1.760 +     // _STLP_ASSERT(__result == __balanced ||
   1.761 +     //              1 == __result->_M_ref_count &&
   1.762 +     //              1 == __balanced->_M_ref_count)
   1.763 +      __result->_M_unref_nonnil();
   1.764      }
   1.765 +    _STLP_UNWIND((_STLP_CREATE_ALLOCATOR(allocator_type,(allocator_type&)__left->_M_size,
   1.766 +                                         _RopeConcatenation).deallocate(__result,1)))
   1.767 +    // In case of exception, we need to deallocate
   1.768 +    // otherwise dangling result node.  But caller
   1.769 +    // still owns its children.  Thus unref is
   1.770 +    // inappropriate.
   1.771 +    return __balanced;
   1.772 +  } else {
   1.773 +    return __result;
   1.774 +  }
   1.775  }
   1.776  
   1.777  template <class _CharT, class _Alloc>
   1.778  __RopeRep__*
   1.779 -rope<_CharT,_Alloc>::_S_concat_char_iter
   1.780 -		(_RopeRep* __r, const _CharT*__s, size_t __slen)
   1.781 -{
   1.782 -    _RopeRep* __result;
   1.783 -    if (0 == __slen) {
   1.784 -	_S_ref(__r);
   1.785 -	return __r;
   1.786 +rope<_CharT,_Alloc>::_S_concat_char_iter (_RopeRep* __r,
   1.787 +                                          const _CharT*__s, size_t __slen) {
   1.788 +  _RopeRep* __result;
   1.789 +  if (0 == __slen) {
   1.790 +    _S_ref(__r);
   1.791 +    return __r;
   1.792 +  }
   1.793 +  if (0 == __r)
   1.794 +    return _S_RopeLeaf_from_unowned_char_ptr(__s, __slen, __r->get_allocator());
   1.795 +  if (_RopeRep::_S_leaf == __r->_M_tag &&
   1.796 +      __r->_M_size._M_data + __slen <= _S_copy_max) {
   1.797 +    __result = _S_leaf_concat_char_iter((_RopeLeaf*)__r, __s, __slen);
   1.798 +    // _STLP_ASSERT(1 == __result->_M_ref_count)
   1.799 +    return __result;
   1.800 +  }
   1.801 +  if (_RopeRep::_S_concat == __r->_M_tag &&
   1.802 +      _RopeRep::_S_leaf == ((_RopeConcatenation*)__r)->_M_right->_M_tag) {
   1.803 +    _RopeLeaf* __right = (_RopeLeaf* )(((_RopeConcatenation* )__r)->_M_right);
   1.804 +    if (__right->_M_size._M_data + __slen <= _S_copy_max) {
   1.805 +      _RopeRep* __left = ((_RopeConcatenation*)__r)->_M_left;
   1.806 +      _RopeRep* __nright = _S_leaf_concat_char_iter((_RopeLeaf*)__right, __s, __slen);
   1.807 +      __left->_M_ref_nonnil();
   1.808 +      _STLP_TRY {
   1.809 +        __result = _S_tree_concat(__left, __nright);
   1.810 +      }
   1.811 +      _STLP_UNWIND(_S_unref(__left); _S_unref(__nright))
   1.812 +      // _STLP_ASSERT(1 == __result->_M_ref_count)
   1.813 +      return __result;
   1.814      }
   1.815 -    if (0 == __r)
   1.816 -      return _STLP_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen,
   1.817 -					      /* __r->get_allocator()*/ allocator_type() );
   1.818 -    if (_RopeRep::_S_leaf == __r->_M_tag && 
   1.819 -          __r->_M_size._M_data + __slen <= _S_copy_max) {
   1.820 -	__result = _S_leaf_concat_char_iter((_RopeLeaf*)__r, __s, __slen);
   1.821 -#       ifndef __GC
   1.822 -	  _STLP_ASSERT(1 == __result->_M_ref_count)
   1.823 -#       endif
   1.824 -	return __result;
   1.825 -    }
   1.826 -    if (_RopeRep::_S_concat == __r->_M_tag
   1.827 -	&& _RopeRep::_S_leaf == ((_RopeConcatenation*)__r)->_M_right->_M_tag) {
   1.828 -	_RopeLeaf* __right = 
   1.829 -	  (_RopeLeaf* )(((_RopeConcatenation* )__r)->_M_right);
   1.830 -	if (__right->_M_size._M_data + __slen <= _S_copy_max) {
   1.831 -	  _RopeRep* __left = ((_RopeConcatenation*)__r)->_M_left;
   1.832 -	  _RopeRep* __nright = 
   1.833 -	    _S_leaf_concat_char_iter((_RopeLeaf*)__right, __s, __slen);
   1.834 -	  __left->_M_ref_nonnil();
   1.835 -	  _STLP_TRY {
   1.836 -	    __result = _S_tree_concat(__left, __nright);
   1.837 -          }
   1.838 -	  _STLP_UNWIND(_S_unref(__left); _S_unref(__nright));
   1.839 -#         ifndef __GC
   1.840 -	    _STLP_ASSERT(1 == __result->_M_ref_count)
   1.841 -#         endif
   1.842 -	  return __result;
   1.843 -	}
   1.844 -    }
   1.845 -    _RopeRep* __nright =
   1.846 -      _STLP_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, __r->get_allocator());
   1.847 -    _STLP_TRY {
   1.848 -      __r->_M_ref_nonnil();
   1.849 -      __result = _S_tree_concat(__r, __nright);
   1.850 -    }
   1.851 -    _STLP_UNWIND(_S_unref(__r); _S_unref(__nright));
   1.852 -#   ifndef __GC
   1.853 -      _STLP_ASSERT(1 == __result->_M_ref_count)
   1.854 -#   endif
   1.855 -    return __result;
   1.856 -}
   1.857 -
   1.858 -#ifndef __GC
   1.859 -template <class _CharT, class _Alloc>
   1.860 -__RopeRep__* 
   1.861 -rope<_CharT,_Alloc>::_S_destr_concat_char_iter(
   1.862 -  _RopeRep* __r, const _CharT* __s, size_t __slen)
   1.863 -{
   1.864 -    _RopeRep* __result;
   1.865 -    if (0 == __r)
   1.866 -      return _STLP_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen,
   1.867 -					      /* __r-> */allocator_type());
   1.868 -    size_t __count = __r->_M_ref_count;
   1.869 -    size_t __orig_size = __r->_M_size._M_data;
   1.870 -    _STLP_ASSERT(__count >= 1)
   1.871 -    if (__count > 1) return _S_concat_char_iter(__r, __s, __slen);
   1.872 -    if (0 == __slen) {
   1.873 -	__r->_M_ref_count = 2;      // One more than before
   1.874 -	return __r;
   1.875 -    }
   1.876 -    if (__orig_size + __slen <= _S_copy_max && 
   1.877 -          _RopeRep::_S_leaf == __r->_M_tag) {
   1.878 -	__result = _S_destr_leaf_concat_char_iter((_RopeLeaf*)__r, __s, __slen);
   1.879 -	return __result;
   1.880 -    }
   1.881 -    if (_RopeRep::_S_concat == __r->_M_tag) {
   1.882 -	_RopeLeaf* __right = (_RopeLeaf*)(((_RopeConcatenation*)__r)->_M_right);
   1.883 -	if (_RopeRep::_S_leaf == __right->_M_tag
   1.884 -	    && __right->_M_size._M_data + __slen <= _S_copy_max) {
   1.885 -	  _RopeRep* __new_right = 
   1.886 -	    _S_destr_leaf_concat_char_iter(__right, __s, __slen);
   1.887 -	  if (__right == __new_right) {
   1.888 -	      _STLP_ASSERT(__new_right->_M_ref_count == 2)
   1.889 -	      __new_right->_M_ref_count = 1;
   1.890 -	  } else {
   1.891 -	      _STLP_ASSERT(__new_right->_M_ref_count >= 1)
   1.892 -	      __right->_M_unref_nonnil();
   1.893 -	  }
   1.894 -	  _STLP_ASSERT(__r->_M_ref_count == 1)
   1.895 -	  __r->_M_ref_count = 2;    // One more than before.
   1.896 -      ((_RopeConcatenation*)__r)->_M_right = __new_right;
   1.897 -      // E.Musser : moved below
   1.898 -      //	  __r->_M_size._M_data = __orig_size + __slen;
   1.899 -	  if (0 != __r->_M_c_string) {
   1.900 -	      __r->_M_free_c_string();
   1.901 -	      __r->_M_c_string = 0;
   1.902 -	  }
   1.903 -	  __r->_M_size._M_data = __orig_size + __slen;
   1.904 -	  return __r;
   1.905 -	}
   1.906 -    }
   1.907 -    _RopeRep* __right =
   1.908 -      _STLP_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, __r->get_allocator());
   1.909 +  }
   1.910 +  _RopeRep* __nright =
   1.911 +    _S_RopeLeaf_from_unowned_char_ptr(__s, __slen, __r->get_allocator());
   1.912 +  _STLP_TRY {
   1.913      __r->_M_ref_nonnil();
   1.914 -    _STLP_TRY {
   1.915 -      __result = _S_tree_concat(__r, __right);
   1.916 -    }
   1.917 -    _STLP_UNWIND(_S_unref(__r); _S_unref(__right))
   1.918 -    _STLP_ASSERT(1 == __result->_M_ref_count)
   1.919 -    return __result;
   1.920 -}
   1.921 -#endif /* !__GC */
   1.922 -
   1.923 -template <class _CharT, class _Alloc>
   1.924 -__RopeRep__*
   1.925 -rope<_CharT,_Alloc>::_S_concat_rep(_RopeRep* __left, _RopeRep* __right)
   1.926 -{
   1.927 -    if (0 == __left) {
   1.928 -	_S_ref(__right);
   1.929 -	return __right;
   1.930 -    }
   1.931 -    if (0 == __right) {
   1.932 -	__left->_M_ref_nonnil();
   1.933 -	return __left;
   1.934 -    }
   1.935 -    if (_RopeRep::_S_leaf == __right->_M_tag) {
   1.936 -	if (_RopeRep::_S_leaf == __left->_M_tag) {
   1.937 -	  if (__right->_M_size._M_data + __left->_M_size._M_data <= _S_copy_max) {
   1.938 -	    return _S_leaf_concat_char_iter((_RopeLeaf*)__left,
   1.939 -					 ((_RopeLeaf*)__right)->_M_data,
   1.940 -					 __right->_M_size._M_data);
   1.941 -	  }
   1.942 -	} else if (_RopeRep::_S_concat == __left->_M_tag
   1.943 -		   && _RopeRep::_S_leaf ==
   1.944 -		      ((_RopeConcatenation*)__left)->_M_right->_M_tag) {
   1.945 -	  _RopeLeaf* __leftright =
   1.946 -		    (_RopeLeaf*)(((_RopeConcatenation*)__left)->_M_right); 
   1.947 -	  if (__leftright->_M_size._M_data + __right->_M_size._M_data <= _S_copy_max) {
   1.948 -	    _RopeRep* __leftleft = ((_RopeConcatenation*)__left)->_M_left;
   1.949 -	    _RopeRep* __rest = _S_leaf_concat_char_iter(__leftright,
   1.950 -					   ((_RopeLeaf*)__right)->_M_data,
   1.951 -					   __right->_M_size._M_data);
   1.952 -	    __leftleft->_M_ref_nonnil();
   1.953 -	    _STLP_TRY {
   1.954 -	      return(_S_tree_concat(__leftleft, __rest));
   1.955 -            }
   1.956 -	    _STLP_UNWIND(_S_unref(__leftleft); _S_unref(__rest))
   1.957 -	  }
   1.958 -	}
   1.959 -    }
   1.960 -    __left->_M_ref_nonnil();
   1.961 -    __right->_M_ref_nonnil();
   1.962 -    _STLP_TRY {
   1.963 -      return(_S_tree_concat(__left, __right));
   1.964 -    }
   1.965 -    _STLP_UNWIND(_S_unref(__left); _S_unref(__right));
   1.966 -#ifdef _STLP_THROW_RETURN_BUG
   1.967 -	return 0;
   1.968 -#endif
   1.969 +    __result = _S_tree_concat(__r, __nright);
   1.970 +  }
   1.971 +  _STLP_UNWIND(_S_unref(__r); _S_unref(__nright))
   1.972 +  // _STLP_ASSERT(1 == __result->_M_ref_count)
   1.973 +  return __result;
   1.974  }
   1.975  
   1.976  template <class _CharT, class _Alloc>
   1.977  __RopeRep__*
   1.978 -rope<_CharT,_Alloc>::_S_substring(_RopeRep* __base, 
   1.979 -                               size_t __start, size_t __endp1)
   1.980 -{
   1.981 -    if (0 == __base) return 0;
   1.982 -    size_t __len = __base->_M_size._M_data;
   1.983 -    size_t __adj_endp1;
   1.984 -    const size_t __lazy_threshold = 128;
   1.985 -    
   1.986 -    if (__endp1 >= __len) {
   1.987 -	if (0 == __start) {
   1.988 -	    __base->_M_ref_nonnil();
   1.989 -	    return __base;
   1.990 -	} else {
   1.991 -	    __adj_endp1 = __len;
   1.992 -	}
   1.993 +rope<_CharT,_Alloc>::_S_destr_concat_char_iter(
   1.994 +  _RopeRep* __r, const _CharT* __s, size_t __slen) {
   1.995 +  _RopeRep* __result;
   1.996 +  if (0 == __r)
   1.997 +    return _S_RopeLeaf_from_unowned_char_ptr(__s, __slen,
   1.998 +                                             __r->get_allocator());
   1.999 +  // size_t __count = __r->_M_ref_count;
  1.1000 +  size_t __orig_size = __r->_M_size._M_data;
  1.1001 +  // _STLP_ASSERT(__count >= 1)
  1.1002 +  if ( /* __count > 1 */ __r->_M_incr() > 2 ) {
  1.1003 +    __r->_M_decr();
  1.1004 +    return _S_concat_char_iter(__r, __s, __slen);
  1.1005 +  }
  1.1006 +  if (0 == __slen) {
  1.1007 +    return __r;
  1.1008 +  }
  1.1009 +  __r->_M_decr();
  1.1010 +  if (__orig_size + __slen <= _S_copy_max && _RopeRep::_S_leaf == __r->_M_tag) {
  1.1011 +    return _S_destr_leaf_concat_char_iter((_RopeLeaf*)__r, __s, __slen);
  1.1012 +  }
  1.1013 +  if (_RopeRep::_S_concat == __r->_M_tag) {
  1.1014 +    _RopeLeaf* __right = __STATIC_CAST(_RopeLeaf*, __STATIC_CAST(_RopeConcatenation*, __r)->_M_right);
  1.1015 +    if (_RopeRep::_S_leaf == __right->_M_tag &&
  1.1016 +        __right->_M_size._M_data + __slen <= _S_copy_max) {
  1.1017 +      _RopeRep* __new_right = _S_destr_leaf_concat_char_iter(__right, __s, __slen);
  1.1018 +      if (__right == __new_right) {
  1.1019 +        // _STLP_ASSERT(__new_right->_M_ref_count == 2)
  1.1020 +        // __new_right->_M_ref_count = 1;
  1.1021 +        __new_right->_M_decr();
  1.1022 +      } else {
  1.1023 +        // _STLP_ASSERT(__new_right->_M_ref_count >= 1)
  1.1024 +        __right->_M_unref_nonnil();
  1.1025 +      }
  1.1026 +      // _STLP_ASSERT(__r->_M_ref_count == 1)
  1.1027 +      // __r->_M_ref_count = 2;    // One more than before.
  1.1028 +      __r->_M_incr();
  1.1029 +      __STATIC_CAST(_RopeConcatenation*, __r)->_M_right = __new_right;
  1.1030 +      // E.Musser : moved below
  1.1031 +      //    __r->_M_size._M_data = __orig_size + __slen;
  1.1032 +      if (0 != __r->_M_c_string) {
  1.1033 +        __r->_M_free_c_string();
  1.1034 +        __r->_M_c_string = 0;
  1.1035 +      }
  1.1036 +      __r->_M_size._M_data = __orig_size + __slen;
  1.1037 +      return __r;
  1.1038 +    }
  1.1039 +  }
  1.1040 +  _RopeRep* __right =
  1.1041 +    _S_RopeLeaf_from_unowned_char_ptr(__s, __slen, __r->get_allocator());
  1.1042 +  __r->_M_ref_nonnil();
  1.1043 +  _STLP_TRY {
  1.1044 +    __result = _S_tree_concat(__r, __right);
  1.1045 +  }
  1.1046 +  _STLP_UNWIND(_S_unref(__r); _S_unref(__right))
  1.1047 +    // _STLP_ASSERT(1 == __result->_M_ref_count)
  1.1048 +  return __result;
  1.1049 +}
  1.1050 +
  1.1051 +template <class _CharT, class _Alloc>
  1.1052 +__RopeRep__*
  1.1053 +rope<_CharT,_Alloc>::_S_concat_rep(_RopeRep* __left, _RopeRep* __right) {
  1.1054 +  if (0 == __left) {
  1.1055 +    _S_ref(__right);
  1.1056 +    return __right;
  1.1057 +  }
  1.1058 +  if (0 == __right) {
  1.1059 +    __left->_M_ref_nonnil();
  1.1060 +    return __left;
  1.1061 +  }
  1.1062 +  if (_RopeRep::_S_leaf == __right->_M_tag) {
  1.1063 +    if (_RopeRep::_S_leaf == __left->_M_tag) {
  1.1064 +      if (__right->_M_size._M_data + __left->_M_size._M_data <= _S_copy_max) {
  1.1065 +        return _S_leaf_concat_char_iter(__STATIC_CAST(_RopeLeaf*, __left),
  1.1066 +                                        __STATIC_CAST(_RopeLeaf*, __right)->_M_data,
  1.1067 +                                        __right->_M_size._M_data);
  1.1068 +      }
  1.1069 +    } else if (_RopeRep::_S_concat == __left->_M_tag &&
  1.1070 +               _RopeRep::_S_leaf == __STATIC_CAST(_RopeConcatenation*, __left)->_M_right->_M_tag) {
  1.1071 +      _RopeLeaf* __leftright =
  1.1072 +        __STATIC_CAST(_RopeLeaf*, __STATIC_CAST(_RopeConcatenation*, __left)->_M_right);
  1.1073 +      if (__leftright->_M_size._M_data + __right->_M_size._M_data <= _S_copy_max) {
  1.1074 +        _RopeRep* __leftleft = __STATIC_CAST(_RopeConcatenation*, __left)->_M_left;
  1.1075 +        _RopeRep* __rest = _S_leaf_concat_char_iter(__leftright,
  1.1076 +                                                    __STATIC_CAST(_RopeLeaf*, __right)->_M_data,
  1.1077 +                                                    __right->_M_size._M_data);
  1.1078 +        __leftleft->_M_ref_nonnil();
  1.1079 +        _STLP_TRY {
  1.1080 +          return _S_tree_concat(__leftleft, __rest);
  1.1081 +        }
  1.1082 +        _STLP_UNWIND(_S_unref(__leftleft); _S_unref(__rest))
  1.1083 +      }
  1.1084 +    }
  1.1085 +  }
  1.1086 +  __left->_M_ref_nonnil();
  1.1087 +  __right->_M_ref_nonnil();
  1.1088 +  _STLP_TRY {
  1.1089 +    return _S_tree_concat(__left, __right);
  1.1090 +  }
  1.1091 +  _STLP_UNWIND(_S_unref(__left); _S_unref(__right))
  1.1092 +  _STLP_RET_AFTER_THROW(0)
  1.1093 +}
  1.1094 +
  1.1095 +template <class _CharT, class _Alloc>
  1.1096 +__RopeRep__*
  1.1097 +rope<_CharT,_Alloc>::_S_substring(_RopeRep* __base,
  1.1098 +                                  size_t __start, size_t __endp1) {
  1.1099 +  if (0 == __base) return 0;
  1.1100 +  size_t __len = __base->_M_size._M_data;
  1.1101 +  size_t __adj_endp1;
  1.1102 +  const size_t __lazy_threshold = 128;
  1.1103 +
  1.1104 +  if (__endp1 >= __len) {
  1.1105 +    if (0 == __start) {
  1.1106 +      __base->_M_ref_nonnil();
  1.1107 +      return __base;
  1.1108      } else {
  1.1109 -	__adj_endp1 = __endp1;
  1.1110 +      __adj_endp1 = __len;
  1.1111      }
  1.1112 -    switch(__base->_M_tag) {
  1.1113 -	case _RopeRep::_S_concat:
  1.1114 -	    {
  1.1115 -		_RopeConcatenation* __c = (_RopeConcatenation*)__base;
  1.1116 -		_RopeRep* __left = __c->_M_left;
  1.1117 -		_RopeRep* __right = __c->_M_right;
  1.1118 -		size_t __left_len = __left->_M_size._M_data;
  1.1119 -		_RopeRep* __result;
  1.1120 +  } else {
  1.1121 +    __adj_endp1 = __endp1;
  1.1122 +  }
  1.1123 +  switch(__base->_M_tag) {
  1.1124 +  case _RopeRep::_S_concat:
  1.1125 +  {
  1.1126 +    _RopeConcatenation* __c = __STATIC_CAST(_RopeConcatenation*, __base);
  1.1127 +    _RopeRep* __left = __c->_M_left;
  1.1128 +    _RopeRep* __right = __c->_M_right;
  1.1129 +    size_t __left_len = __left->_M_size._M_data;
  1.1130 +    _RopeRep* __result;
  1.1131  
  1.1132 -		if (__adj_endp1 <= __left_len) {
  1.1133 -		    return _S_substring(__left, __start, __endp1);
  1.1134 -		} else if (__start >= __left_len) {
  1.1135 -		    return _S_substring(__right, __start - __left_len,
  1.1136 -				  __adj_endp1 - __left_len);
  1.1137 -		}
  1.1138 -		_Self_destruct_ptr __left_result(
  1.1139 -		  _S_substring(__left, __start, __left_len));
  1.1140 -		_Self_destruct_ptr __right_result(
  1.1141 -		  _S_substring(__right, 0, __endp1 - __left_len));
  1.1142 -		_STLP_MPWFIX_TRY		//*TY 06/01/2000 - mpw forgets to call dtor on __left_result and __right_result without this try block
  1.1143 -		__result = _S_concat_rep(__left_result, __right_result);
  1.1144 -#               ifndef __GC
  1.1145 -		  _STLP_ASSERT(1 == __result->_M_ref_count)
  1.1146 -#               endif
  1.1147 -		return __result;
  1.1148 -		_STLP_MPWFIX_CATCH		//*TY 06/01/2000 - 
  1.1149 -	    }
  1.1150 -	case _RopeRep::_S_leaf:
  1.1151 -	    {
  1.1152 -		_RopeLeaf* __l = (_RopeLeaf*)__base;
  1.1153 -		_RopeLeaf* __result;
  1.1154 -		size_t __result_len;
  1.1155 -		if (__start >= __adj_endp1) return 0;
  1.1156 -		__result_len = __adj_endp1 - __start;
  1.1157 -		if (__result_len > __lazy_threshold) goto lazy;
  1.1158 -#               ifdef __GC
  1.1159 -		    const _CharT* __section = __l->_M_data + __start;
  1.1160 -		    __result = _S_new_RopeLeaf(__section, __result_len,
  1.1161 -					  __base->get_allocator());
  1.1162 -		    __result->_M_c_string = 0;  // Not eos terminated.
  1.1163 -#               else
  1.1164 -		    // We should sometimes create substring node instead.
  1.1165 -		    __result = _STLP_ROPE_FROM_UNOWNED_CHAR_PTR(
  1.1166 -					__l->_M_data + __start, __result_len,
  1.1167 -					__base->get_allocator());
  1.1168 -#               endif
  1.1169 -		return __result;
  1.1170 -	    }
  1.1171 -	case _RopeRep::_S_substringfn:
  1.1172 -	    // Avoid introducing multiple layers of substring nodes.
  1.1173 -	    {
  1.1174 -		_RopeSubstring* __old = (_RopeSubstring*)__base;
  1.1175 -		size_t __result_len;
  1.1176 -		if (__start >= __adj_endp1) return 0;
  1.1177 -		__result_len = __adj_endp1 - __start;
  1.1178 -		if (__result_len > __lazy_threshold) {
  1.1179 -		    _RopeSubstring* __result =
  1.1180 -			_S_new_RopeSubstring(__old->_M_base,
  1.1181 -					  __start + __old->_M_start,
  1.1182 -					  __adj_endp1 - __start,
  1.1183 -					  __base->get_allocator());
  1.1184 -		    return __result;
  1.1185 +    if (__adj_endp1 <= __left_len) {
  1.1186 +      return _S_substring(__left, __start, __endp1);
  1.1187 +    } else if (__start >= __left_len) {
  1.1188 +      return _S_substring(__right, __start - __left_len,
  1.1189 +                          __adj_endp1 - __left_len);
  1.1190 +    }
  1.1191 +    _Self_destruct_ptr __left_result(_S_substring(__left, __start, __left_len));
  1.1192 +    _Self_destruct_ptr __right_result(_S_substring(__right, 0, __endp1 - __left_len));
  1.1193 +    _STLP_MPWFIX_TRY    //*TY 06/01/2000 - mpw forgets to call dtor on __left_result and __right_result without this try block
  1.1194 +    __result = _S_concat_rep(__left_result, __right_result);
  1.1195 +    // _STLP_ASSERT(1 == __result->_M_ref_count)
  1.1196 +    return __result;
  1.1197 +    _STLP_MPWFIX_CATCH    //*TY 06/01/2000 -
  1.1198 +  }
  1.1199 +  case _RopeRep::_S_leaf:
  1.1200 +  {
  1.1201 +    _RopeLeaf* __l = __STATIC_CAST(_RopeLeaf*, __base);
  1.1202 +    _RopeLeaf* __result;
  1.1203 +    size_t __result_len;
  1.1204 +    if (__start >= __adj_endp1) return 0;
  1.1205 +    __result_len = __adj_endp1 - __start;
  1.1206 +    if (__result_len > __lazy_threshold) goto lazy;
  1.1207 +    const _CharT* __section = __l->_M_data + __start;
  1.1208 +    // We should sometimes create substring node instead.
  1.1209 +    __result = _S_RopeLeaf_from_unowned_char_ptr(__section, __result_len,
  1.1210 +                                                 __base->get_allocator());
  1.1211 +    return __result;
  1.1212 +  }
  1.1213 +  case _RopeRep::_S_substringfn:
  1.1214 +  // Avoid introducing multiple layers of substring nodes.
  1.1215 +  {
  1.1216 +    _RopeSubstring* __old = __STATIC_CAST(_RopeSubstring*, __base);
  1.1217 +    size_t __result_len;
  1.1218 +    if (__start >= __adj_endp1) return 0;
  1.1219 +    __result_len = __adj_endp1 - __start;
  1.1220 +    if (__result_len > __lazy_threshold) {
  1.1221 +      _RopeSubstring* __result = _S_new_RopeSubstring(__old->_M_base,
  1.1222 +                                                      __start + __old->_M_start,
  1.1223 +                                                      __adj_endp1 - __start,
  1.1224 +                                                      __base->get_allocator());
  1.1225 +      return __result;
  1.1226 +    } // *** else fall through: ***
  1.1227 +  }
  1.1228 +  case _RopeRep::_S_function:
  1.1229 +  {
  1.1230 +    _RopeFunction* __f = __STATIC_CAST(_RopeFunction*, __base);
  1.1231 +    if (__start >= __adj_endp1) return 0;
  1.1232 +    size_t __result_len = __adj_endp1 - __start;
  1.1233  
  1.1234 -		} // *** else fall through: ***
  1.1235 -	    }
  1.1236 -	case _RopeRep::_S_function:
  1.1237 -	    {
  1.1238 -		_RopeFunction* __f = (_RopeFunction*)__base;
  1.1239 -		if (__start >= __adj_endp1) return 0;
  1.1240 -		size_t __result_len = __adj_endp1 - __start;
  1.1241 -
  1.1242 -		if (__result_len > __lazy_threshold) goto lazy;
  1.1243 -		_CharT* __section = __base->_M_size.allocate(_S_rounded_up_size(__result_len));
  1.1244 -		_STLP_TRY {
  1.1245 -		  (*(__f->_M_fn))(__start, __result_len, __section);
  1.1246 -                }
  1.1247 -		_STLP_UNWIND(_RopeRep::_S_free_string(
  1.1248 -	               __section, __result_len, __base->get_allocator()));
  1.1249 -		_S_cond_store_eos(__section[__result_len]);
  1.1250 -		return _S_new_RopeLeaf(__section, __result_len,
  1.1251 -				       __base->get_allocator());
  1.1252 -	    }
  1.1253 +    if (__result_len > __lazy_threshold) goto lazy;
  1.1254 +    _CharT* __section = __base->_M_size.allocate(_S_rounded_up_size(__result_len));
  1.1255 +    _STLP_TRY {
  1.1256 +      (*(__f->_M_fn))(__start, __result_len, __section);
  1.1257      }
  1.1258 -    /*NOTREACHED*/
  1.1259 -    _STLP_ASSERT(false)
  1.1260 +    _STLP_UNWIND(_RopeRep::_S_free_string(__section,
  1.1261 +                                          __result_len, __base->get_allocator()))
  1.1262 +    _S_construct_null(__section + __result_len);
  1.1263 +    return _S_new_RopeLeaf(__section, __result_len,
  1.1264 +                           __base->get_allocator());
  1.1265 +  }
  1.1266 +  }
  1.1267 +  /*NOTREACHED*/
  1.1268 +  _STLP_ASSERT(false)
  1.1269    lazy:
  1.1270 -    {
  1.1271 -	// Create substring node.
  1.1272 -	return _S_new_RopeSubstring(__base, __start, __adj_endp1 - __start,
  1.1273 -			       __base->get_allocator());
  1.1274 -    }
  1.1275 +  {
  1.1276 +    // Create substring node.
  1.1277 +    return _S_new_RopeSubstring(__base, __start, __adj_endp1 - __start,
  1.1278 +                                __base->get_allocator());
  1.1279 +  }
  1.1280  }
  1.1281  
  1.1282  template<class _CharT>
  1.1283  class _Rope_flatten_char_consumer : public _Rope_char_consumer<_CharT> {
  1.1284 -    private:
  1.1285 -	_CharT* _M_buf_ptr;
  1.1286 -    public:
  1.1287 -	//  _CharT* _M_buffer;  // XXX not used
  1.1288 +private:
  1.1289 +  _CharT* _M_buf_ptr;
  1.1290 +public:
  1.1291 +  _Rope_flatten_char_consumer(_CharT* __buffer) {
  1.1292 +    _M_buf_ptr = __buffer;
  1.1293 +  }
  1.1294 +  ~_Rope_flatten_char_consumer() {}
  1.1295 +  bool operator() (const _CharT* __leaf, size_t __n) {
  1.1296 +    _STLP_PRIV __ucopy_n(__leaf, __n, _M_buf_ptr);
  1.1297 +    _M_buf_ptr += __n;
  1.1298 +    return true;
  1.1299 +  }
  1.1300 +};
  1.1301  
  1.1302 -	_Rope_flatten_char_consumer(_CharT* __buffer) {
  1.1303 -	    _M_buf_ptr = __buffer;
  1.1304 -	};
  1.1305 -	~_Rope_flatten_char_consumer() {}
  1.1306 -	bool operator() (const _CharT* __leaf, size_t __n) {
  1.1307 -	    uninitialized_copy_n(__leaf, __n, _M_buf_ptr);
  1.1308 -	    _M_buf_ptr += __n;
  1.1309 -	    return true;
  1.1310 -	}
  1.1311 -};
  1.1312 -	    
  1.1313  template<class _CharT>
  1.1314  class _Rope_find_char_char_consumer : public _Rope_char_consumer<_CharT> {
  1.1315 -    private:
  1.1316 -	_CharT _M_pattern;
  1.1317 -    public:
  1.1318 -	size_t _M_count;  // Number of nonmatching characters
  1.1319 -	_Rope_find_char_char_consumer(_CharT __p) 
  1.1320 -	  : _M_pattern(__p), _M_count(0) {}
  1.1321 -	~_Rope_find_char_char_consumer() {}
  1.1322 -	bool operator() (const _CharT* __leaf, size_t __n) {
  1.1323 -	    size_t __i;
  1.1324 -	    for (__i = 0; __i < __n; __i++) {
  1.1325 -		if (__leaf[__i] == _M_pattern) {
  1.1326 -		    _M_count += __i; return false;
  1.1327 -		}
  1.1328 -	    }
  1.1329 -	    _M_count += __n; return true;
  1.1330 -	}
  1.1331 +private:
  1.1332 +  _CharT _M_pattern;
  1.1333 +public:
  1.1334 +  size_t _M_count;  // Number of nonmatching characters
  1.1335 +  _Rope_find_char_char_consumer(_CharT __p)
  1.1336 +    : _M_pattern(__p), _M_count(0) {}
  1.1337 +  ~_Rope_find_char_char_consumer() {}
  1.1338 +  bool operator() (const _CharT* __leaf, size_t __n) {
  1.1339 +    size_t __i;
  1.1340 +    for (__i = 0; __i < __n; ++__i) {
  1.1341 +      if (__leaf[__i] == _M_pattern) {
  1.1342 +        _M_count += __i; return false;
  1.1343 +      }
  1.1344 +    }
  1.1345 +    _M_count += __n; return true;
  1.1346 +  }
  1.1347  };
  1.1348  
  1.1349 -#if !defined (_STLP_USE_NO_IOSTREAMS)	    
  1.1350 -#if defined (_STLP_USE_NEW_IOSTREAMS)
  1.1351 -  template<class _CharT, class _Traits>
  1.1352 -  // Here _CharT is both the stream and rope character type.
  1.1353 -#else
  1.1354 - template<class _CharT>
  1.1355 -  // Here _CharT is the rope character type.  Unlike in the
  1.1356 -  // above case, we somewhat handle the case in which it doesn't
  1.1357 -  // match the stream character type, i.e. char.
  1.1358 -#endif
  1.1359 +#if !defined (_STLP_USE_NO_IOSTREAMS)
  1.1360 +template<class _CharT, class _Traits>
  1.1361 +// Here _CharT is both the stream and rope character type.
  1.1362  class _Rope_insert_char_consumer : public _Rope_char_consumer<_CharT> {
  1.1363 -    private:
  1.1364 -#       if defined (_STLP_USE_NEW_IOSTREAMS)
  1.1365 -	  typedef basic_ostream<_CharT,_Traits> _Insert_ostream;
  1.1366 -#	else
  1.1367 - 	typedef ostream _Insert_ostream;
  1.1368 -#	endif
  1.1369 -	_Insert_ostream& _M_o;
  1.1370 -    public:
  1.1371 -	// _CharT* buffer;    // XXX not used
  1.1372 -	_Rope_insert_char_consumer(_Insert_ostream& __writer) 
  1.1373 -	  : _M_o(__writer) {};
  1.1374 -#if defined(__MRC__)||(defined(__SC__) && !defined(__DMC__))		//*TY 05/23/2000 - added support for mpw compiler's trigger function approach to generate vtable
  1.1375 -  ~_Rope_insert_char_consumer();		//*TY 05/23/2000 - 
  1.1376 -#else		//*TY 05/23/2000 - 
  1.1377 +private:
  1.1378 +  typedef basic_ostream<_CharT,_Traits> _Insert_ostream;
  1.1379 +  typedef _Rope_insert_char_consumer<_CharT,_Traits> _Self;
  1.1380 +  _Insert_ostream& _M_o;
  1.1381 +
  1.1382 +  //explicitely defined as private to avoid warnings:
  1.1383 +  _Self& operator = (_Self const&);
  1.1384 +public:
  1.1385 +  _Rope_insert_char_consumer(_Insert_ostream& __writer)
  1.1386 +    : _M_o(__writer) {}
  1.1387 +#  if defined(__MRC__) || (defined(__SC__) && !defined(__DMC__))  //*TY 05/23/2000 - added support for mpw compiler's trigger function approach to generate vtable
  1.1388 +  ~_Rope_insert_char_consumer();    //*TY 05/23/2000 -
  1.1389 +#  else    //*TY 05/23/2000 -
  1.1390    ~_Rope_insert_char_consumer() {}
  1.1391 -#endif		//*TY 05/23/2000 - 
  1.1392 -		// Caller is presumed to own the ostream
  1.1393 -	bool operator() (const _CharT* __leaf, size_t __n);
  1.1394 -		// Returns true to continue traversal.
  1.1395 +#  endif    //*TY 05/23/2000 -
  1.1396 +  // Caller is presumed to own the ostream
  1.1397 +  bool operator() (const _CharT* __leaf, size_t __n);
  1.1398 +  // Returns true to continue traversal.
  1.1399  };
  1.1400 -	    
  1.1401 -# if defined ( _STLP_USE_NEW_IOSTREAMS )
  1.1402 -#  if defined(__MRC__)||(defined(__SC__) && !defined(__DMC__))		//*TY 05/23/2000 - added support for mpw compiler's trigger function approach to generate vtable
  1.1403 -  template<class _CharT, class _Traits>
  1.1404 -  _Rope_insert_char_consumer<_CharT, _Traits>::  ~_Rope_insert_char_consumer() {}
  1.1405 -#  endif		//*TY 05/23/2000 - 
  1.1406  
  1.1407 -  template<class _CharT, class _Traits>
  1.1408 -  bool _Rope_insert_char_consumer<_CharT, _Traits>::operator()
  1.1409 -					(const _CharT* __leaf, size_t __n)
  1.1410 -{
  1.1411 -    size_t __i;
  1.1412 -    //  We assume that formatting is set up correctly for each element.
  1.1413 -    for (__i = 0; __i < __n; __i++) _M_o.put(__leaf[__i]);
  1.1414 -    return true;
  1.1415 +#  if defined (__MRC__) || (defined (__SC__) && !defined (__DMC__))    //*TY 05/23/2000 - added support for mpw compiler's trigger function approach to generate vtable
  1.1416 +template<class _CharT, class _Traits>
  1.1417 +_Rope_insert_char_consumer<_CharT, _Traits>::  ~_Rope_insert_char_consumer() {}
  1.1418 +#  endif    //*TY 05/23/2000 -
  1.1419 +
  1.1420 +template<class _CharT, class _Traits>
  1.1421 +bool _Rope_insert_char_consumer<_CharT, _Traits>::operator()
  1.1422 +  (const _CharT* __leaf, size_t __n) {
  1.1423 +  size_t __i;
  1.1424 +  //  We assume that formatting is set up correctly for each element.
  1.1425 +  for (__i = 0; __i < __n; ++__i) _M_o.put(__leaf[__i]);
  1.1426 +  return true;
  1.1427  }
  1.1428 -# else
  1.1429 -#  if defined(__MRC__)||(defined(__SC__) && !defined(__DMC__))		//*TY 05/23/2000 - added support for mpw compiler's trigger function approach to generate vtable
  1.1430 -  template<class _CharT>
  1.1431 -  _Rope_insert_char_consumer<_CharT>::  ~_Rope_insert_char_consumer() {}
  1.1432 -#  endif		//*TY 05/23/2000 - 
  1.1433 +#endif /* !_STLP_USE_NO_IOSTREAMS */
  1.1434  
  1.1435 -  template<class _CharT>
  1.1436 -  bool _Rope_insert_char_consumer<_CharT>::operator()
  1.1437 -					(const _CharT* __leaf, size_t __n)
  1.1438 +template <class _CharT, class _Alloc, class _CharConsumer>
  1.1439 +bool _S_apply_to_pieces(_CharConsumer& __c,
  1.1440 +                        _Rope_RopeRep<_CharT, _Alloc> * __r,
  1.1441 +                        size_t __begin, size_t __end) {
  1.1442 +  typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
  1.1443 +  typedef _Rope_RopeConcatenation<_CharT,_Alloc> _RopeConcatenation;
  1.1444 +  typedef _Rope_RopeLeaf<_CharT,_Alloc> _RopeLeaf;
  1.1445 +  typedef _Rope_RopeFunction<_CharT,_Alloc> _RopeFunction;
  1.1446 +
  1.1447 +  if (0 == __r) return true;
  1.1448 +  switch(__r->_M_tag) {
  1.1449 +  case _RopeRep::_S_concat:
  1.1450    {
  1.1451 -    size_t __i;
  1.1452 -    //  We assume that formatting is set up correctly for each element.
  1.1453 -    for (__i = 0; __i < __n; __i++) _M_o << __leaf[__i];
  1.1454 -    return true;
  1.1455 +    _RopeConcatenation* __conc = __STATIC_CAST(_RopeConcatenation*, __r);
  1.1456 +    _RopeRep* __left =  __conc->_M_left;
  1.1457 +    size_t __left_len = __left->_M_size._M_data;
  1.1458 +    if (__begin < __left_len) {
  1.1459 +      size_t __left_end = (min) (__left_len, __end);
  1.1460 +      if (!_S_apply_to_pieces(__c, __left, __begin, __left_end))
  1.1461 +        return false;
  1.1462 +    }
  1.1463 +    if (__end > __left_len) {
  1.1464 +      _RopeRep* __right =  __conc->_M_right;
  1.1465 +      size_t __right_start = (max)(__left_len, __begin);
  1.1466 +      if (!_S_apply_to_pieces(__c, __right,
  1.1467 +                              __right_start - __left_len,
  1.1468 +                              __end - __left_len)) {
  1.1469 +        return false;
  1.1470 +      }
  1.1471 +    }
  1.1472    }
  1.1473 -
  1.1474 -# if !defined (_STLP_NO_METHOD_SPECIALIZATION)
  1.1475 -_STLP_TEMPLATE_NULL
  1.1476 -inline bool 
  1.1477 -_Rope_insert_char_consumer<char>::operator()
  1.1478 -					(const char* __leaf, size_t __n)
  1.1479 -{
  1.1480 -    size_t __i;
  1.1481 -    for (__i = 0; __i < __n; __i++) _M_o.put(__leaf[__i]);
  1.1482 -    return true;
  1.1483 +  return true;
  1.1484 +  case _RopeRep::_S_leaf:
  1.1485 +  {
  1.1486 +    _RopeLeaf* __l = __STATIC_CAST(_RopeLeaf*, __r);
  1.1487 +    return __c(__l->_M_data + __begin, __end - __begin);
  1.1488 +  }
  1.1489 +  case _RopeRep::_S_function:
  1.1490 +  case _RopeRep::_S_substringfn:
  1.1491 +  {
  1.1492 +    _RopeFunction* __f = __STATIC_CAST(_RopeFunction*, __r);
  1.1493 +    size_t __len = __end - __begin;
  1.1494 +    bool __result;
  1.1495 +    _CharT* __buffer = __r->get_allocator().allocate(__len);
  1.1496 +    _STLP_TRY {
  1.1497 +      (*(__f->_M_fn))(__begin, __len, __buffer);
  1.1498 +      __result = __c(__buffer, __len);
  1.1499 +      __r->get_allocator().deallocate(__buffer, __len);
  1.1500 +    }
  1.1501 +    _STLP_UNWIND((__r->get_allocator().deallocate(__buffer, __len)))
  1.1502 +    return __result;
  1.1503 +  }
  1.1504 +  default:
  1.1505 +    _STLP_ASSERT(false)
  1.1506 +    /*NOTREACHED*/
  1.1507 +    return false;
  1.1508 +  }
  1.1509  }
  1.1510  
  1.1511 -#endif /* _STLP_METHOD_SPECIALIZATION */
  1.1512 -#endif /* _STLP_USE_NEW_IOSTREAM */
  1.1513 -#endif /* if !defined (_STLP_USE_NO_IOSTREAMS) */
  1.1514 -
  1.1515 -template <class _CharT, class _Alloc>
  1.1516 -bool rope<_CharT, _Alloc>::_S_apply_to_pieces(
  1.1517 -				_Rope_char_consumer<_CharT>& __c,
  1.1518 -				const _RopeRep* __r,
  1.1519 -				size_t __begin, size_t __end)
  1.1520 -{
  1.1521 -    if (0 == __r) return true;
  1.1522 -    switch(__r->_M_tag) {
  1.1523 -	case _RopeRep::_S_concat:
  1.1524 -	    {
  1.1525 -		_RopeConcatenation* __conc = (_RopeConcatenation*)__r;
  1.1526 -		_RopeRep* __left =  __conc->_M_left;
  1.1527 -		size_t __left_len = __left->_M_size._M_data;
  1.1528 -		if (__begin < __left_len) {
  1.1529 -		    size_t __left_end = (min) (__left_len, __end);
  1.1530 -		    if (!_S_apply_to_pieces(__c, __left, __begin, __left_end))
  1.1531 -			return false;
  1.1532 -		}
  1.1533 -		if (__end > __left_len) {
  1.1534 -		    _RopeRep* __right =  __conc->_M_right;
  1.1535 -		    size_t __right_start = (max)(__left_len, __begin);
  1.1536 -		    if (!_S_apply_to_pieces(__c, __right,
  1.1537 -					 __right_start - __left_len,
  1.1538 -					 __end - __left_len)) {
  1.1539 -			return false;
  1.1540 -		    }
  1.1541 -		}
  1.1542 -	    }
  1.1543 -	    return true;
  1.1544 -	case _RopeRep::_S_leaf:
  1.1545 -	    {
  1.1546 -		_RopeLeaf* __l = (_RopeLeaf*)__r;
  1.1547 -		return __c.operator()(__l->_M_data + __begin, __end - __begin);
  1.1548 -	    }
  1.1549 -	case _RopeRep::_S_function:
  1.1550 -	case _RopeRep::_S_substringfn:
  1.1551 -	    {
  1.1552 -		_RopeFunction* __f = (_RopeFunction*)__r;
  1.1553 -		size_t __len = __end - __begin;
  1.1554 -#ifdef __SYMBIAN32__
  1.1555 -		bool __result = false;
  1.1556 -#else
  1.1557 -		bool __result;
  1.1558 -#endif
  1.1559 -		_CharT* __buffer =
  1.1560 -		  (_CharT*)__sgi_alloc::allocate(__len * sizeof(_CharT));
  1.1561 -		_STLP_TRY {
  1.1562 -		  (*(__f->_M_fn))(__begin, __len, __buffer);
  1.1563 -		  __result = __c.operator()(__buffer, __len);
  1.1564 -                  __sgi_alloc::deallocate(__buffer, __len * sizeof(_CharT));
  1.1565 -                }
  1.1566 -		_STLP_UNWIND((__sgi_alloc::deallocate(__buffer,
  1.1567 -						      __len * sizeof(_CharT))))
  1.1568 -		return __result;
  1.1569 -	    }
  1.1570 -	default:
  1.1571 -	    _STLP_ASSERT(false)
  1.1572 -	    /*NOTREACHED*/
  1.1573 -	    return false;
  1.1574 -    }
  1.1575 +#if !defined (_STLP_USE_NO_IOSTREAMS)
  1.1576 +template<class _CharT, class _Traits>
  1.1577 +inline void _Rope_fill(basic_ostream<_CharT, _Traits>& __o, streamsize __n) {
  1.1578 +  char __f = __o.fill();
  1.1579 +  for (streamsize __i = 0; __i < __n; ++__i) __o.put(__f);
  1.1580  }
  1.1581  
  1.1582 -template <class _CharT> inline bool _Rope_is_simple(_CharT*) { return false; }
  1.1583 -inline bool _Rope_is_simple(char*) { return true; }
  1.1584 -# ifdef _STLP_HAS_WCHAR_T
  1.1585 -inline bool _Rope_is_simple(wchar_t*) { return true; }
  1.1586 -# endif
  1.1587 +template<class _CharT, class _Traits, class _Alloc>
  1.1588 +basic_ostream<_CharT, _Traits>& _S_io_get(basic_ostream<_CharT, _Traits>& __o,
  1.1589 +                                          const rope<_CharT, _Alloc>& __r, const __true_type& /*_IsBasicCharType*/) {
  1.1590 +  streamsize __w = __o.width();
  1.1591 +  const bool __left = (__o.flags() & ios::left) != 0;
  1.1592 +  size_t __rope_len = __r.size();
  1.1593 +  _Rope_insert_char_consumer<_CharT, _Traits> __c(__o);
  1.1594  
  1.1595 -#if !defined (_STLP_USE_NO_IOSTREAMS)
  1.1596 -#if defined (_STLP_USE_NEW_IOSTREAMS)
  1.1597 -  template<class _CharT, class _Traits>
  1.1598 -  inline void _Rope_fill(basic_ostream<_CharT, _Traits>& __o, size_t __n)
  1.1599 -#else
  1.1600 -inline void _Rope_fill(ostream& __o, size_t __n)
  1.1601 -#endif
  1.1602 -{
  1.1603 -    char __f = __o.fill();
  1.1604 -    size_t __i;
  1.1605 +  const bool __need_pad = (((sizeof(streamsize) > sizeof(size_t)) && (__STATIC_CAST(streamsize, __rope_len) < __w)) ||
  1.1606 +                           ((sizeof(streamsize) <= sizeof(size_t)) && (__rope_len < __STATIC_CAST(size_t, __w))));
  1.1607 +  streamsize __pad_len = __need_pad ? __w - __rope_len : 0;
  1.1608  
  1.1609 -    for (__i = 0; __i < __n; __i++) __o.put(__f);
  1.1610 -}
  1.1611 -    
  1.1612 -#if defined (_STLP_USE_NEW_IOSTREAMS)
  1.1613 -  template<class _CharT, class _Traits, class _Alloc>
  1.1614 -  basic_ostream<_CharT, _Traits>& operator<<
  1.1615 -					(basic_ostream<_CharT, _Traits>& __o,
  1.1616 -					 const rope<_CharT, _Alloc>& __r)
  1.1617 -# else
  1.1618 -template<class _CharT, class _Alloc>
  1.1619 -ostream& operator<< (ostream& __o, const rope<_CharT, _Alloc>& __r)
  1.1620 -#endif
  1.1621 -{
  1.1622 -    size_t __w = __o.width();
  1.1623 -    bool __left = bool(__o.flags() & ios::left);
  1.1624 -    size_t __pad_len;
  1.1625 -    size_t __rope_len = __r.size();
  1.1626 -#   if defined (_STLP_USE_NEW_IOSTREAMS)
  1.1627 -      _Rope_insert_char_consumer<_CharT, _Traits> __c(__o);
  1.1628 -#   else
  1.1629 -    _Rope_insert_char_consumer<_CharT> __c(__o);
  1.1630 -#   endif
  1.1631 -    bool __is_simple = _Rope_is_simple((_CharT*)0);
  1.1632 -    
  1.1633 -    if (__rope_len < __w) {
  1.1634 -	__pad_len = __w - __rope_len;
  1.1635 -    } else {
  1.1636 -	__pad_len = 0;
  1.1637 -    }
  1.1638 -    if (!__is_simple) __o.width(__w/__rope_len);
  1.1639 -    _STLP_TRY {
  1.1640 -      if (__is_simple && !__left && __pad_len > 0) {
  1.1641 -	_Rope_fill(__o, __pad_len);
  1.1642 -      }
  1.1643 -      __r.apply_to_pieces(0, __r.size(), __c);
  1.1644 -      if (__is_simple && __left && __pad_len > 0) {
  1.1645 -	_Rope_fill(__o, __pad_len);
  1.1646 -      }
  1.1647 -      if (!__is_simple)
  1.1648 -        __o.width(__w);
  1.1649 -    }
  1.1650 -    _STLP_UNWIND(if (!__is_simple) __o.width(__w))
  1.1651 -    return __o;
  1.1652 +  if (!__left && __pad_len > 0) {
  1.1653 +    _Rope_fill(__o, __pad_len);
  1.1654 +  }
  1.1655 +  __r.apply_to_pieces(0, __rope_len, __c);
  1.1656 +  if (__left && __pad_len > 0) {
  1.1657 +    _Rope_fill(__o, __pad_len);
  1.1658 +  }
  1.1659 +  return __o;
  1.1660  }
  1.1661  
  1.1662 +template<class _CharT, class _Traits, class _Alloc>
  1.1663 +basic_ostream<_CharT, _Traits>& _S_io_get(basic_ostream<_CharT, _Traits>& __o,
  1.1664 +                                         const rope<_CharT, _Alloc>& __r, const __false_type& /*_IsBasicCharType*/) {
  1.1665 +  streamsize __w = __o.width();
  1.1666 +  size_t __rope_len = __r.size();
  1.1667 +  _Rope_insert_char_consumer<_CharT, _Traits> __c(__o);
  1.1668 +
  1.1669 +  __o.width(__w /__rope_len);
  1.1670 +  _STLP_TRY {
  1.1671 +    __r.apply_to_pieces(0, __rope_len, __c);
  1.1672 +    __o.width(__w);
  1.1673 +  }
  1.1674 +  _STLP_UNWIND(__o.width(__w))
  1.1675 +  return __o;
  1.1676 +}
  1.1677 +
  1.1678 +template<class _CharT, class _Traits, class _Alloc>
  1.1679 +basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __o,
  1.1680 +                                           const rope<_CharT, _Alloc>& __r) {
  1.1681 +  typedef typename _IsIntegral<_CharT>::_Ret _Char_Is_Integral;
  1.1682 +  return _S_io_get(__o, __r, _Char_Is_Integral());
  1.1683 +}
  1.1684  #endif /* NO_IOSTREAMS */
  1.1685  
  1.1686  template <class _CharT, class _Alloc>
  1.1687 -_CharT*
  1.1688 -rope<_CharT,_Alloc>::_S_flatten(_RopeRep* __r,
  1.1689 -				 size_t __start, size_t __len,
  1.1690 -				 _CharT* __buffer)
  1.1691 -{
  1.1692 -    _Rope_flatten_char_consumer<_CharT> __c(__buffer);
  1.1693 -    _S_apply_to_pieces(__c, __r, __start, __start + __len);
  1.1694 -    return(__buffer + __len);
  1.1695 +_CharT* rope<_CharT,_Alloc>::_S_flatten(_RopeRep* __r,
  1.1696 +                                        size_t __start, size_t __len,
  1.1697 +                                        _CharT* __buffer) {
  1.1698 +  _Rope_flatten_char_consumer<_CharT> __c(__buffer);
  1.1699 +  _S_apply_to_pieces(__c, __r, __start, __start + __len);
  1.1700 +  return(__buffer + __len);
  1.1701  }
  1.1702  
  1.1703  template <class _CharT, class _Alloc>
  1.1704 -size_t
  1.1705 -rope<_CharT,_Alloc>::find(_CharT __pattern, size_t __start) const
  1.1706 -{
  1.1707 -    _Rope_find_char_char_consumer<_CharT> __c(__pattern);
  1.1708 -    _S_apply_to_pieces(__c, _M_tree_ptr._M_data, __start, size());
  1.1709 -    size_type __result_pos = __start + __c._M_count;
  1.1710 -#   ifndef _STLP_OLD_ROPE_SEMANTICS
  1.1711 -	if (__result_pos == size()) __result_pos = npos;
  1.1712 -#   endif
  1.1713 -    return __result_pos;
  1.1714 +size_t rope<_CharT,_Alloc>::find(_CharT __pattern, size_t __start) const {
  1.1715 +  _Rope_find_char_char_consumer<_CharT> __c(__pattern);
  1.1716 +  _S_apply_to_pieces(__c, _M_tree_ptr._M_data, __start, size());
  1.1717 +  size_type __result_pos = __start + __c._M_count;
  1.1718 +#ifndef _STLP_OLD_ROPE_SEMANTICS
  1.1719 +  if (__result_pos == size()) __result_pos = npos;
  1.1720 +#endif
  1.1721 +  return __result_pos;
  1.1722  }
  1.1723  
  1.1724  template <class _CharT, class _Alloc>
  1.1725  _CharT*
  1.1726 -rope<_CharT,_Alloc>::_S_flatten(_Rope_RopeRep<_CharT, _Alloc>* __r, _CharT* __buffer)
  1.1727 -{
  1.1728 -    if (0 == __r) return __buffer;
  1.1729 -    switch(__r->_M_tag) {
  1.1730 -	case _RopeRep::_S_concat:
  1.1731 -	    {
  1.1732 -		_RopeConcatenation* __c = (_RopeConcatenation*)__r;
  1.1733 -		_RopeRep* __left = __c->_M_left;
  1.1734 -		_RopeRep* __right = __c->_M_right;
  1.1735 -		_CharT* __rest = _S_flatten(__left, __buffer);
  1.1736 -		return _S_flatten(__right, __rest);
  1.1737 -	    }
  1.1738 -	case _RopeRep::_S_leaf:
  1.1739 -	    {
  1.1740 -		_RopeLeaf* __l = (_RopeLeaf*)__r;
  1.1741 -		return copy_n(__l->_M_data, __l->_M_size._M_data, __buffer).second;
  1.1742 -	    }
  1.1743 -	case _RopeRep::_S_function:
  1.1744 -	case _RopeRep::_S_substringfn:
  1.1745 -	    // We dont yet do anything with substring nodes.
  1.1746 -	    // This needs to be fixed before ropefiles will work well.
  1.1747 -	    {
  1.1748 -		_RopeFunction* __f = (_RopeFunction*)__r;
  1.1749 -		(*(__f->_M_fn))(0, __f->_M_size._M_data, __buffer);
  1.1750 -		return __buffer + __f->_M_size._M_data;
  1.1751 -	    }
  1.1752 -	default:
  1.1753 -	    _STLP_ASSERT(false)
  1.1754 -	    /*NOTREACHED*/
  1.1755 -	    return 0;
  1.1756 -    }
  1.1757 +rope<_CharT,_Alloc>::_S_flatten(_Rope_RopeRep<_CharT, _Alloc>* __r, _CharT* __buffer) {
  1.1758 +  if (0 == __r) return __buffer;
  1.1759 +  switch(__r->_M_tag) {
  1.1760 +  case _RopeRep::_S_concat:
  1.1761 +  {
  1.1762 +    _RopeConcatenation* __c = __STATIC_CAST(_RopeConcatenation*, __r);
  1.1763 +    _RopeRep* __left = __c->_M_left;
  1.1764 +    _RopeRep* __right = __c->_M_right;
  1.1765 +    _CharT* __rest = _S_flatten(__left, __buffer);
  1.1766 +    return _S_flatten(__right, __rest);
  1.1767 +  }
  1.1768 +  case _RopeRep::_S_leaf:
  1.1769 +  {
  1.1770 +    _RopeLeaf* __l = __STATIC_CAST(_RopeLeaf*, __r);
  1.1771 +    return _STLP_PRIV __ucopy_n(__l->_M_data, __l->_M_size._M_data, __buffer).second;
  1.1772 +  }
  1.1773 +  case _RopeRep::_S_function:
  1.1774 +  case _RopeRep::_S_substringfn:
  1.1775 +  // We dont yet do anything with substring nodes.
  1.1776 +  // This needs to be fixed before ropefiles will work well.
  1.1777 +  {
  1.1778 +    _RopeFunction* __f = __STATIC_CAST(_RopeFunction*, __r);
  1.1779 +    (*(__f->_M_fn))(0, __f->_M_size._M_data, __buffer);
  1.1780 +    return __buffer + __f->_M_size._M_data;
  1.1781 +  }
  1.1782 +  default:
  1.1783 +    _STLP_ASSERT(false)
  1.1784 +    /*NOTREACHED*/
  1.1785 +    return 0;
  1.1786 +  }
  1.1787  }
  1.1788  
  1.1789 -
  1.1790 +#ifdef _STLP_DEBUG
  1.1791  // This needs work for _CharT != char
  1.1792  template <class _CharT, class _Alloc>
  1.1793 -void
  1.1794 -rope<_CharT,_Alloc>::_S_dump(_RopeRep* __r, int __indent)
  1.1795 -{
  1.1796 -    for (int __i = 0; __i < __indent; __i++) putchar(' ');
  1.1797 -    if (0 == __r) {
  1.1798 -      printf("NULL\n"); return;
  1.1799 +void rope<_CharT,_Alloc>::_S_dump(_RopeRep* __r, int __indent) {
  1.1800 +  for (int __i = 0; __i < __indent; ++__i) putchar(' ');
  1.1801 +  if (0 == __r) {
  1.1802 +    printf("NULL\n"); return;
  1.1803 +  }
  1.1804 +  if (_RopeRep::_S_concat == __r->_M_tag) {
  1.1805 +    _RopeConcatenation* __c = __STATIC_CAST(_RopeConcatenation*, __r);
  1.1806 +    _RopeRep* __left = __c->_M_left;
  1.1807 +    _RopeRep* __right = __c->_M_right;
  1.1808 +    printf("Concatenation %p (rc = %ld, depth = %d, len = %ld, %s balanced)\n",
  1.1809 +      __r, __r->_M_ref_count, __r->_M_depth, __r->_M_size._M_data,
  1.1810 +      __r->_M_is_balanced? "" : "not");
  1.1811 +    _S_dump(__left, __indent + 2);
  1.1812 +    _S_dump(__right, __indent + 2);
  1.1813 +    return;
  1.1814 +  }
  1.1815 +  else {
  1.1816 +    const char* __kind;
  1.1817 +
  1.1818 +    switch (__r->_M_tag) {
  1.1819 +      case _RopeRep::_S_leaf:
  1.1820 +        __kind = "Leaf";
  1.1821 +        break;
  1.1822 +      case _RopeRep::_S_function:
  1.1823 +        __kind = "Function";
  1.1824 +        break;
  1.1825 +      case _RopeRep::_S_substringfn:
  1.1826 +        __kind = "Function representing substring";
  1.1827 +        break;
  1.1828 +      default:
  1.1829 +        __kind = "(corrupted kind field!)";
  1.1830      }
  1.1831 -    if (_RopeRep::_S_concat == __r->_M_tag) {
  1.1832 -	_RopeConcatenation* __c = (_RopeConcatenation*)__r;
  1.1833 -	_RopeRep* __left = __c->_M_left;
  1.1834 -	_RopeRep* __right = __c->_M_right;
  1.1835 +    printf("%s %p (rc = %ld, depth = %d, len = %ld) ",
  1.1836 +     __kind, __r, __r->_M_ref_count, __r->_M_depth, __r->_M_size._M_data);
  1.1837 +    if (sizeof(_CharT) == 1) {
  1.1838 +      const int __max_len = 40;
  1.1839 +      _Self_destruct_ptr __prefix(_S_substring(__r, 0, __max_len));
  1.1840 +      _CharT __buffer[__max_len + 1];
  1.1841 +      bool __too_big = __r->_M_size._M_data > __prefix->_M_size._M_data;
  1.1842  
  1.1843 -#       ifdef __GC
  1.1844 -	  printf("Concatenation %p (depth = %d, len = %ld, %s balanced)\n",
  1.1845 -	    __r, __r->_M_depth, __r->_M_size._M_data, __r->_M_is_balanced? "" : "not");
  1.1846 -#       else
  1.1847 -	  printf("Concatenation %p (rc = %ld, depth = %d, "
  1.1848 -	           "len = %ld, %s balanced)\n",
  1.1849 -		 __r, __r->_M_ref_count, __r->_M_depth, __r->_M_size._M_data,
  1.1850 -		 __r->_M_is_balanced? "" : "not");
  1.1851 -#       endif
  1.1852 -	_S_dump(__left, __indent + 2);
  1.1853 -	_S_dump(__right, __indent + 2);
  1.1854 -	return;
  1.1855 +      _S_flatten(__prefix, __buffer);
  1.1856 +      __buffer[__prefix->_M_size._M_data] = _STLP_DEFAULT_CONSTRUCTED(_CharT);
  1.1857 +      printf("%s%s\n", (char*)__buffer, __too_big? "...\n" : "\n");
  1.1858      } else {
  1.1859 -	const char* __kind;
  1.1860 -
  1.1861 -	switch (__r->_M_tag) {
  1.1862 -	    case _RopeRep::_S_leaf:
  1.1863 -		__kind = "Leaf";
  1.1864 -		break;
  1.1865 -	    case _RopeRep::_S_function:
  1.1866 -		__kind = "Function";
  1.1867 -		break;
  1.1868 -	    case _RopeRep::_S_substringfn:
  1.1869 -		__kind = "Function representing substring";
  1.1870 -		break;
  1.1871 -	    default:
  1.1872 -		__kind = "(corrupted kind field!)";
  1.1873 -	}
  1.1874 -#       ifdef __GC
  1.1875 -	  printf("%s %p (depth = %d, len = %ld) ",
  1.1876 -		 __kind, __r, __r->_M_depth, __r->_M_size._M_data);
  1.1877 -#       else
  1.1878 -	  printf("%s %p (rc = %ld, depth = %d, len = %ld) ",
  1.1879 -		 __kind, __r, __r->_M_ref_count, __r->_M_depth, __r->_M_size._M_data);
  1.1880 -#       endif
  1.1881 -	if (_S_is_one_byte_char_type((_CharT*)0)) {
  1.1882 -	    const int __max_len = 40;
  1.1883 -	    _Self_destruct_ptr __prefix(_S_substring(__r, 0, __max_len));
  1.1884 -	    _CharT __buffer[__max_len + 1];
  1.1885 -	    bool __too_big = __r->_M_size._M_data > __prefix->_M_size._M_data;
  1.1886 -
  1.1887 -	    _S_flatten(__prefix, __buffer);
  1.1888 -	    __buffer[__prefix->_M_size._M_data] = _S_eos((_CharT*)0); 
  1.1889 -	    printf("%s%s\n", 
  1.1890 -	           (char*)__buffer, __too_big? "...\n" : "\n");
  1.1891 -	} else {
  1.1892 -	    printf("\n");
  1.1893 -	}
  1.1894 +      printf("\n");
  1.1895      }
  1.1896 +  }
  1.1897  }
  1.1898 +#endif /* _STLP_DEBUG */
  1.1899  
  1.1900  # define __ROPE_TABLE_BODY  = { \
  1.1901  /* 0 */1, /* 1 */2, /* 2 */3, /* 3 */5, /* 4 */8, /* 5 */13, /* 6 */21,         \
  1.1902 @@ -1118,13 +1021,13 @@
  1.1903  # if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
  1.1904  template <class _CharT, class _Alloc>
  1.1905  const unsigned long
  1.1906 -rope<_CharT,_Alloc>::_S_min_len[__ROPE_DEPTH_SIZE] __ROPE_TABLE_BODY ;
  1.1907 -# else 
  1.1908 -__DECLARE_INSTANCE(const unsigned long, 
  1.1909 +rope<_CharT,_Alloc>::_S_min_len[__ROPE_DEPTH_SIZE] __ROPE_TABLE_BODY;
  1.1910 +# else
  1.1911 +__DECLARE_INSTANCE(const unsigned long,
  1.1912                     crope::_S_min_len[__ROPE_DEPTH_SIZE],
  1.1913                     __ROPE_TABLE_BODY);
  1.1914  #  ifndef _STLP_NO_WCHAR_T
  1.1915 -__DECLARE_INSTANCE(const unsigned long, 
  1.1916 +__DECLARE_INSTANCE(const unsigned long,
  1.1917                     wrope::_S_min_len[__ROPE_DEPTH_SIZE],
  1.1918                     __ROPE_TABLE_BODY);
  1.1919  #  endif
  1.1920 @@ -1136,38 +1039,34 @@
  1.1921  // These are Fibonacci numbers < 2**32.
  1.1922  
  1.1923  template <class _CharT, class _Alloc>
  1.1924 -__RopeRep__*
  1.1925 -rope<_CharT,_Alloc>::_S_balance(_RopeRep* __r)
  1.1926 -{
  1.1927 -    _RopeRep* __forest[_RopeRep::_S_max_rope_depth + 1];
  1.1928 -    _RopeRep* __result = 0;
  1.1929 -    int __i;
  1.1930 -    // Invariant:
  1.1931 -    // The concatenation of forest in descending order is equal to __r.
  1.1932 -    // __forest[__i]._M_size._M_data >= _S_min_len[__i]
  1.1933 -    // __forest[__i]._M_depth = __i
  1.1934 -    // References from forest are included in refcount.
  1.1935 +__RopeRep__* rope<_CharT,_Alloc>::_S_balance(_RopeRep* __r) {
  1.1936 +  _RopeRep* __forest[_RopeRep::_S_max_rope_depth + 1] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  1.1937 +                                                         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  1.1938 +                                                         0,0,0,0,0,0};
  1.1939 +  _RopeRep* __result = 0;
  1.1940 +  int __i;
  1.1941 +  // Invariant:
  1.1942 +  // The concatenation of forest in descending order is equal to __r.
  1.1943 +  // __forest[__i]._M_size._M_data >= _S_min_len[__i]
  1.1944 +  // __forest[__i]._M_depth = __i
  1.1945 +  // References from forest are included in refcount.
  1.1946  
  1.1947 -    for (__i = 0; __i <= _RopeRep::_S_max_rope_depth; ++__i) 
  1.1948 -      __forest[__i] = 0;
  1.1949 -    _STLP_TRY {
  1.1950 -      _S_add_to_forest(__r, __forest);
  1.1951 -      for (__i = 0; __i <= _RopeRep::_S_max_rope_depth; ++__i) 
  1.1952 -        if (0 != __forest[__i]) {
  1.1953 -#	ifndef __GC
  1.1954 -	  _Self_destruct_ptr __old(__result);
  1.1955 -#	endif
  1.1956 -	  __result = _S_concat_rep(__forest[__i], __result);
  1.1957 -	__forest[__i]->_M_unref_nonnil();
  1.1958 -#	if !defined(__GC) && defined(_STLP_USE_EXCEPTIONS)
  1.1959 -	  __forest[__i] = 0;
  1.1960 -#	endif
  1.1961 +  _STLP_TRY {
  1.1962 +    _S_add_to_forest(__r, __forest);
  1.1963 +    for (__i = 0; __i <= _RopeRep::_S_max_rope_depth; ++__i)
  1.1964 +      if (0 != __forest[__i]) {
  1.1965 +        _Self_destruct_ptr __old(__result);
  1.1966 +        __result = _S_concat_rep(__forest[__i], __result);
  1.1967 +        __forest[__i]->_M_unref_nonnil();
  1.1968 +# ifdef _STLP_USE_EXCEPTIONS
  1.1969 +        __forest[__i] = 0;
  1.1970 +# endif
  1.1971        }
  1.1972      }
  1.1973 -    _STLP_UNWIND(for(__i = 0; __i <= _RopeRep::_S_max_rope_depth; __i++)
  1.1974 -		 _S_unref(__forest[__i]))
  1.1975 +    _STLP_UNWIND(for(__i = 0; __i <= _RopeRep::_S_max_rope_depth; ++__i)
  1.1976 +    _S_unref(__forest[__i]))
  1.1977      if (__result->_M_depth > _RopeRep::_S_max_rope_depth) {
  1.1978 -	__stl_throw_range_error("rope too long");
  1.1979 +      __stl_throw_range_error("rope too long");
  1.1980      }
  1.1981      return(__result);
  1.1982  }
  1.1983 @@ -1178,15 +1077,15 @@
  1.1984  rope<_CharT,_Alloc>::_S_add_to_forest(_RopeRep* __r, _RopeRep** __forest)
  1.1985  {
  1.1986      if (__r -> _M_is_balanced) {
  1.1987 -	_S_add_leaf_to_forest(__r, __forest);
  1.1988 -	return;
  1.1989 +      _S_add_leaf_to_forest(__r, __forest);
  1.1990 +      return;
  1.1991      }
  1.1992      _STLP_ASSERT(__r->_M_tag == _RopeRep::_S_concat)
  1.1993      {
  1.1994 -	_RopeConcatenation* __c = (_RopeConcatenation*)__r;
  1.1995 +      _RopeConcatenation* __c = (_RopeConcatenation*)__r;
  1.1996  
  1.1997 -	_S_add_to_forest(__c->_M_left, __forest);
  1.1998 -	_S_add_to_forest(__c->_M_right, __forest);
  1.1999 +      _S_add_to_forest(__c->_M_left, __forest);
  1.2000 +      _S_add_to_forest(__c->_M_right, __forest);
  1.2001      }
  1.2002  }
  1.2003  
  1.2004 @@ -1195,49 +1094,43 @@
  1.2005  void
  1.2006  rope<_CharT,_Alloc>::_S_add_leaf_to_forest(_RopeRep* __r, _RopeRep** __forest)
  1.2007  {
  1.2008 -    _RopeRep* __insertee;   		// included in refcount
  1.2009 -    _RopeRep* __too_tiny = 0;    	// included in refcount
  1.2010 -    int __i;  				// forest[0..__i-1] is empty
  1.2011 +    _RopeRep* __insertee;       // included in refcount
  1.2012 +    _RopeRep* __too_tiny = 0;      // included in refcount
  1.2013 +    int __i;          // forest[0..__i-1] is empty
  1.2014      size_t __s = __r->_M_size._M_data;
  1.2015  
  1.2016      for (__i = 0; __s >= _S_min_len[__i+1]/* not this bucket */; ++__i) {
  1.2017 -	if (0 != __forest[__i]) {
  1.2018 -#	    ifndef __GC
  1.2019 -	      _Self_destruct_ptr __old(__too_tiny);
  1.2020 -#	    endif
  1.2021 -	    __too_tiny = _S_concat_and_set_balanced(__forest[__i], __too_tiny);
  1.2022 -	    __forest[__i]->_M_unref_nonnil();
  1.2023 -	    __forest[__i] = 0;
  1.2024 -	}
  1.2025 +  if (0 != __forest[__i]) {
  1.2026 +        _Self_destruct_ptr __old(__too_tiny);
  1.2027 +      __too_tiny = _S_concat_and_set_balanced(__forest[__i], __too_tiny);
  1.2028 +      __forest[__i]->_M_unref_nonnil();
  1.2029 +      __forest[__i] = 0;
  1.2030 +  }
  1.2031      }
  1.2032      {
  1.2033 -#	ifndef __GC
  1.2034 -	  _Self_destruct_ptr __old(__too_tiny);
  1.2035 -#	endif
  1.2036 -	__insertee = _S_concat_and_set_balanced(__too_tiny, __r);
  1.2037 +    _Self_destruct_ptr __old(__too_tiny);
  1.2038 +  __insertee = _S_concat_and_set_balanced(__too_tiny, __r);
  1.2039      }
  1.2040      // Too_tiny dead, and no longer included in refcount.
  1.2041      // Insertee is live and included.
  1.2042      _STLP_ASSERT(_S_is_almost_balanced(__insertee))
  1.2043      _STLP_ASSERT(__insertee->_M_depth <= __r->_M_depth + 1)
  1.2044      for (;; ++__i) {
  1.2045 -	if (0 != __forest[__i]) {
  1.2046 -#	    ifndef __GC
  1.2047 -	      _Self_destruct_ptr __old(__insertee);
  1.2048 -#	    endif
  1.2049 -	    __insertee = _S_concat_and_set_balanced(__forest[__i], __insertee);
  1.2050 -	    __forest[__i]->_M_unref_nonnil();
  1.2051 -	    __forest[__i] = 0;
  1.2052 -	    _STLP_ASSERT(_S_is_almost_balanced(__insertee))
  1.2053 -	}
  1.2054 -	_STLP_ASSERT(_S_min_len[__i] <= __insertee->_M_size._M_data)
  1.2055 -	_STLP_ASSERT(__forest[__i] == 0)
  1.2056 -	if (__i == _RopeRep::_S_max_rope_depth || 
  1.2057 -	      __insertee->_M_size._M_data < _S_min_len[__i+1]) {
  1.2058 -	    __forest[__i] = __insertee;
  1.2059 -	    // refcount is OK since __insertee is now dead.
  1.2060 -	    return;
  1.2061 -	}
  1.2062 +      if (0 != __forest[__i]) {
  1.2063 +        _Self_destruct_ptr __old(__insertee);
  1.2064 +      __insertee = _S_concat_and_set_balanced(__forest[__i], __insertee);
  1.2065 +      __forest[__i]->_M_unref_nonnil();
  1.2066 +      __forest[__i] = 0;
  1.2067 +      _STLP_ASSERT(_S_is_almost_balanced(__insertee))
  1.2068 +  }
  1.2069 +  _STLP_ASSERT(_S_min_len[__i] <= __insertee->_M_size._M_data)
  1.2070 +  _STLP_ASSERT(__forest[__i] == 0)
  1.2071 +  if (__i == _RopeRep::_S_max_rope_depth ||
  1.2072 +        __insertee->_M_size._M_data < _S_min_len[__i+1]) {
  1.2073 +      __forest[__i] = __insertee;
  1.2074 +      // refcount is OK since __insertee is now dead.
  1.2075 +      return;
  1.2076 +  }
  1.2077      }
  1.2078  }
  1.2079  
  1.2080 @@ -1245,40 +1138,40 @@
  1.2081  _CharT
  1.2082  rope<_CharT,_Alloc>::_S_fetch(_RopeRep* __r, size_type __i)
  1.2083  {
  1.2084 -    __GC_CONST _CharT* __cstr = __r->_M_c_string;
  1.2085 +    _CharT* __cstr = __r->_M_c_string;
  1.2086  
  1.2087      _STLP_ASSERT(__i < __r->_M_size._M_data)
  1.2088 -    if (0 != __cstr) return __cstr[__i]; 
  1.2089 +    if (0 != __cstr) return __cstr[__i];
  1.2090      for(;;) {
  1.2091        switch(__r->_M_tag) {
  1.2092 -	case _RopeRep::_S_concat:
  1.2093 -	    {
  1.2094 -		_RopeConcatenation* __c = (_RopeConcatenation*)__r;
  1.2095 -		_RopeRep* __left = __c->_M_left;
  1.2096 -		size_t __left_len = __left->_M_size._M_data;
  1.2097 +  case _RopeRep::_S_concat:
  1.2098 +      {
  1.2099 +    _RopeConcatenation* __c = (_RopeConcatenation*)__r;
  1.2100 +    _RopeRep* __left = __c->_M_left;
  1.2101 +    size_t __left_len = __left->_M_size._M_data;
  1.2102  
  1.2103 -		if (__i >= __left_len) {
  1.2104 -		    __i -= __left_len;
  1.2105 -		    __r = __c->_M_right;
  1.2106 -		} else {
  1.2107 -		    __r = __left;
  1.2108 -		}
  1.2109 -	    }
  1.2110 -	    break;
  1.2111 -	case _RopeRep::_S_leaf:
  1.2112 -	    {
  1.2113 -		_RopeLeaf* __l = (_RopeLeaf*)__r;
  1.2114 -		return __l->_M_data[__i];
  1.2115 -	    }
  1.2116 -	case _RopeRep::_S_function:
  1.2117 -	case _RopeRep::_S_substringfn:
  1.2118 -	    {
  1.2119 -		_RopeFunction* __f = (_RopeFunction*)__r;
  1.2120 -		_CharT __result;
  1.2121 +    if (__i >= __left_len) {
  1.2122 +        __i -= __left_len;
  1.2123 +        __r = __c->_M_right;
  1.2124 +    } else {
  1.2125 +        __r = __left;
  1.2126 +    }
  1.2127 +      }
  1.2128 +      break;
  1.2129 +  case _RopeRep::_S_leaf:
  1.2130 +      {
  1.2131 +    _RopeLeaf* __l = (_RopeLeaf*)__r;
  1.2132 +    return __l->_M_data[__i];
  1.2133 +      }
  1.2134 +  case _RopeRep::_S_function:
  1.2135 +  case _RopeRep::_S_substringfn:
  1.2136 +      {
  1.2137 +    _RopeFunction* __f = (_RopeFunction*)__r;
  1.2138 +    _CharT __result;
  1.2139  
  1.2140 -		(*(__f->_M_fn))(__i, 1, &__result);
  1.2141 -		return __result;
  1.2142 -	    }
  1.2143 +    (*(__f->_M_fn))(__i, 1, &__result);
  1.2144 +    return __result;
  1.2145 +      }
  1.2146        }
  1.2147      }
  1.2148  #if defined(_STLP_NEED_UNREACHABLE_RETURN)
  1.2149 @@ -1286,7 +1179,6 @@
  1.2150  #endif
  1.2151  }
  1.2152  
  1.2153 -# ifndef __GC
  1.2154  // Return a uniquely referenced character slot for the given
  1.2155  // position, or 0 if that's not possible.
  1.2156  template <class _CharT, class _Alloc>
  1.2157 @@ -1297,39 +1189,43 @@
  1.2158      size_t __csptr = 0;
  1.2159  
  1.2160      for(;;) {
  1.2161 -      if (__r->_M_ref_count > 1) return 0;
  1.2162 +      // if (__r->_M_ref_count > 1) return 0;
  1.2163 +      if ( __r->_M_incr() > 2 ) {
  1.2164 +        __r->_M_decr();
  1.2165 +        return 0;
  1.2166 +      }
  1.2167        switch(__r->_M_tag) {
  1.2168 -	case _RopeRep::_S_concat:
  1.2169 -	    {
  1.2170 -		_RopeConcatenation* __c = (_RopeConcatenation*)__r;
  1.2171 -		_RopeRep* __left = __c->_M_left;
  1.2172 -		size_t __left_len = __left->_M_size._M_data;
  1.2173 +  case _RopeRep::_S_concat:
  1.2174 +      {
  1.2175 +    _RopeConcatenation* __c = (_RopeConcatenation*)__r;
  1.2176 +    _RopeRep* __left = __c->_M_left;
  1.2177 +    size_t __left_len = __left->_M_size._M_data;
  1.2178  
  1.2179 -		if (__c->_M_c_string != 0) __clrstack[__csptr++] = __c;
  1.2180 -		if (__i >= __left_len) {
  1.2181 -		    __i -= __left_len;
  1.2182 -		    __r = __c->_M_right;
  1.2183 -		} else {
  1.2184 -		    __r = __left;
  1.2185 -		}
  1.2186 -	    }
  1.2187 -	    break;
  1.2188 -	case _RopeRep::_S_leaf:
  1.2189 -	    {
  1.2190 -		_RopeLeaf* __l = (_RopeLeaf*)__r;
  1.2191 -		if (__l->_M_c_string != __l->_M_data && __l->_M_c_string != 0)
  1.2192 -		    __clrstack[__csptr++] = __l;
  1.2193 -		while (__csptr > 0) {
  1.2194 -		    -- __csptr;
  1.2195 -		    _RopeRep* __d = __clrstack[__csptr];
  1.2196 -		    __d->_M_free_c_string();
  1.2197 -		    __d->_M_c_string = 0;
  1.2198 -		}
  1.2199 -		return __l->_M_data + __i;
  1.2200 -	    }
  1.2201 -	case _RopeRep::_S_function:
  1.2202 -	case _RopeRep::_S_substringfn:
  1.2203 -	    return 0;
  1.2204 +    if (__c->_M_c_string != 0) __clrstack[__csptr++] = __c;
  1.2205 +    if (__i >= __left_len) {
  1.2206 +        __i -= __left_len;
  1.2207 +        __r = __c->_M_right;
  1.2208 +    } else {
  1.2209 +        __r = __left;
  1.2210 +    }
  1.2211 +      }
  1.2212 +      break;
  1.2213 +  case _RopeRep::_S_leaf:
  1.2214 +      {
  1.2215 +    _RopeLeaf* __l = (_RopeLeaf*)__r;
  1.2216 +    if (__l->_M_c_string != __l->_M_data && __l->_M_c_string != 0)
  1.2217 +        __clrstack[__csptr++] = __l;
  1.2218 +    while (__csptr > 0) {
  1.2219 +        -- __csptr;
  1.2220 +        _RopeRep* __d = __clrstack[__csptr];
  1.2221 +        __d->_M_free_c_string();
  1.2222 +        __d->_M_c_string = 0;
  1.2223 +    }
  1.2224 +    return __l->_M_data + __i;
  1.2225 +      }
  1.2226 +  case _RopeRep::_S_function:
  1.2227 +  case _RopeRep::_S_substringfn:
  1.2228 +      return 0;
  1.2229        }
  1.2230      }
  1.2231  #if defined(_STLP_NEED_UNREACHABLE_RETURN)
  1.2232 @@ -1337,7 +1233,6 @@
  1.2233  #endif
  1.2234  
  1.2235  }
  1.2236 -# endif /* __GC */
  1.2237  
  1.2238  // The following could be implemented trivially using
  1.2239  // lexicographical_compare_3way.
  1.2240 @@ -1345,46 +1240,43 @@
  1.2241  // flat strings.
  1.2242  template <class _CharT, class _Alloc>
  1.2243  int
  1.2244 -rope<_CharT,_Alloc>::_S_compare (const _RopeRep* __left, 
  1.2245 -                                 const _RopeRep* __right)
  1.2246 -{
  1.2247 -    size_t __left_len;
  1.2248 -    size_t __right_len;
  1.2249 +rope<_CharT,_Alloc>::_S_compare (const _RopeRep* __left,
  1.2250 +                                 const _RopeRep* __right) {
  1.2251 +  size_t __left_len;
  1.2252 +  size_t __right_len;
  1.2253  
  1.2254 -    if (0 == __right) return 0 != __left;
  1.2255 -    if (0 == __left) return -1;
  1.2256 -    __left_len = __left->_M_size._M_data;
  1.2257 -    __right_len = __right->_M_size._M_data;
  1.2258 -    if (_RopeRep::_S_leaf == __left->_M_tag) {
  1.2259 -	_RopeLeaf* __l = (_RopeLeaf*) __left;
  1.2260 -	if (_RopeRep::_S_leaf == __right->_M_tag) {
  1.2261 -	    _RopeLeaf* __r = (_RopeLeaf*) __right;
  1.2262 -	    return lexicographical_compare_3way(
  1.2263 -			__l->_M_data, __l->_M_data + __left_len,
  1.2264 -			__r->_M_data, __r->_M_data + __right_len);
  1.2265 -	} else {
  1.2266 -	    const_iterator __rstart(__right, 0);
  1.2267 -	    const_iterator __rend(__right, __right_len);
  1.2268 -	    return lexicographical_compare_3way(
  1.2269 -			__l->_M_data, __l->_M_data + __left_len,
  1.2270 -			__rstart, __rend);
  1.2271 -	}
  1.2272 -    } else {
  1.2273 -	const_iterator __lstart(__left, 0);
  1.2274 -	const_iterator __lend(__left, __left_len);
  1.2275 -	if (_RopeRep::_S_leaf == __right->_M_tag) {
  1.2276 -	    _RopeLeaf* __r = (_RopeLeaf*) __right;
  1.2277 -	    return lexicographical_compare_3way(
  1.2278 -				   __lstart, __lend,
  1.2279 -				   __r->_M_data, __r->_M_data + __right_len);
  1.2280 -	} else {
  1.2281 -	    const_iterator __rstart(__right, 0);
  1.2282 -	    const_iterator __rend(__right, __right_len);
  1.2283 -	    return lexicographical_compare_3way(
  1.2284 -				   __lstart, __lend,
  1.2285 -				   __rstart, __rend);
  1.2286 -	}
  1.2287 +  if (0 == __right) return 0 != __left;
  1.2288 +  if (0 == __left) return -1;
  1.2289 +  __left_len = __left->_M_size._M_data;
  1.2290 +  __right_len = __right->_M_size._M_data;
  1.2291 +  if (_RopeRep::_S_leaf == __left->_M_tag) {
  1.2292 +    const _RopeLeaf* __l = __STATIC_CAST(const _RopeLeaf*, __left);
  1.2293 +    if (_RopeRep::_S_leaf == __right->_M_tag) {
  1.2294 +      const _RopeLeaf* __r = __STATIC_CAST(const _RopeLeaf*, __right);
  1.2295 +      return _STLP_PRIV __lexicographical_compare_3way(__l->_M_data, __l->_M_data + __left_len,
  1.2296 +                                                       __r->_M_data, __r->_M_data + __right_len);
  1.2297      }
  1.2298 +    else {
  1.2299 +      const_iterator __rstart(__right, 0);
  1.2300 +      const_iterator __rend(__right, __right_len);
  1.2301 +      return _STLP_PRIV __lexicographical_compare_3way(__l->_M_data, __l->_M_data + __left_len,
  1.2302 +                                                       __rstart, __rend);
  1.2303 +    }
  1.2304 +  }
  1.2305 +  else {
  1.2306 +    const_iterator __lstart(__left, 0);
  1.2307 +    const_iterator __lend(__left, __left_len);
  1.2308 +    if (_RopeRep::_S_leaf == __right->_M_tag) {
  1.2309 +      const _RopeLeaf* __r = __STATIC_CAST(const _RopeLeaf*, __right);
  1.2310 +      return _STLP_PRIV __lexicographical_compare_3way(__lstart, __lend,
  1.2311 +                                                       __r->_M_data, __r->_M_data + __right_len);
  1.2312 +    }
  1.2313 +    else {
  1.2314 +      const_iterator __rstart(__right, 0);
  1.2315 +      const_iterator __rend(__right, __right_len);
  1.2316 +      return _STLP_PRIV __lexicographical_compare_3way(__lstart, __lend, __rstart, __rend);
  1.2317 +    }
  1.2318 +  }
  1.2319  }
  1.2320  
  1.2321  // Assignment to reference proxies.
  1.2322 @@ -1392,15 +1284,13 @@
  1.2323  _Rope_char_ref_proxy<_CharT, _Alloc>&
  1.2324  _Rope_char_ref_proxy<_CharT, _Alloc>::operator= (_CharT __c) {
  1.2325      _RopeRep* __old = _M_root->_M_tree_ptr._M_data;
  1.2326 -#   ifndef __GC
  1.2327 -	// First check for the case in which everything is uniquely
  1.2328 -	// referenced.  In that case we can do this destructively.
  1.2329 -	_CharT* __ptr = _My_rope::_S_fetch_ptr(__old, _M_pos);
  1.2330 -	if (0 != __ptr) {
  1.2331 -	    *__ptr = __c;
  1.2332 -	    return *this;
  1.2333 -	}
  1.2334 -#   endif
  1.2335 +  // First check for the case in which everything is uniquely
  1.2336 +  // referenced.  In that case we can do this destructively.
  1.2337 +  _CharT* __ptr = _My_rope::_S_fetch_ptr(__old, _M_pos);
  1.2338 +  if (0 != __ptr) {
  1.2339 +      *__ptr = __c;
  1.2340 +      return *this;
  1.2341 +  }
  1.2342      _Self_destruct_ptr __left(
  1.2343        _My_rope::_S_substring(__old, 0, _M_pos));
  1.2344      _Self_destruct_ptr __right(
  1.2345 @@ -1408,15 +1298,11 @@
  1.2346      _Self_destruct_ptr __result_left(
  1.2347        _My_rope::_S_destr_concat_char_iter(__left, &__c, 1));
  1.2348  
  1.2349 -#   ifndef __GC
  1.2350 -      _STLP_ASSERT(__left == __result_left || 1 == __result_left->_M_ref_count)
  1.2351 -#   endif
  1.2352 +    // _STLP_ASSERT(__left == __result_left || 1 == __result_left->_M_ref_count)
  1.2353      _RopeRep* __result =
  1.2354        _My_rope::_S_concat_rep(__result_left, __right);
  1.2355 -#   ifndef __GC
  1.2356 -      _STLP_ASSERT(1 <= __result->_M_ref_count)
  1.2357 -      _RopeRep::_S_unref(__old);
  1.2358 -#   endif
  1.2359 +    // _STLP_ASSERT(1 <= __result->_M_ref_count)
  1.2360 +    _RopeRep::_S_unref(__old);
  1.2361      _M_root->_M_tree_ptr._M_data = __result;
  1.2362      return *this;
  1.2363  }
  1.2364 @@ -1438,78 +1324,80 @@
  1.2365  # endif /* _STLP_STATIC_TEMPLATE_DATA */
  1.2366  // # endif
  1.2367  
  1.2368 +#if !defined (_STLP_STATIC_CONST_INIT_BUG)
  1.2369 +#  if !defined (__GNUC__) || (__GNUC__ != 2) || (__GNUC_MINOR__ != 96)
  1.2370 +template <class _CharT, class _Alloc>
  1.2371 +const size_t rope<_CharT, _Alloc>::npos;
  1.2372 +#  endif
  1.2373 +#endif
  1.2374 +
  1.2375  template<class _CharT, class _Alloc>
  1.2376  const _CharT* rope<_CharT,_Alloc>::c_str() const {
  1.2377 -    if (0 == _M_tree_ptr._M_data) {
  1.2378 -        _S_empty_c_str[0] = _S_eos((_CharT*)0);  // Possibly redundant,
  1.2379 -					     // but probably fast.
  1.2380 -        return _S_empty_c_str;
  1.2381 -    }
  1.2382 -    __GC_CONST _CharT* __old_c_string = _M_tree_ptr._M_data->_M_c_string;
  1.2383 -    if (0 != __old_c_string) return(__old_c_string);
  1.2384 -    size_t __s = size();
  1.2385 -   _CharT* __result = _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_tree_ptr, _CharT).allocate(__s + 1);
  1.2386 -    _S_flatten(_M_tree_ptr._M_data, __result);
  1.2387 -    __result[__s] = _S_eos((_CharT*)0);
  1.2388 -#   ifdef __GC
  1.2389 -	_M_tree_ptr._M_data->_M_c_string = __result;
  1.2390 -#   else
  1.2391 -      if ((__old_c_string = (__GC_CONST _CharT*)
  1.2392 -	   _Atomic_swap((__stl_atomic_t *)(&(_M_tree_ptr._M_data->_M_c_string)),
  1.2393 -			(__stl_atomic_t)__result)) != 0) {
  1.2394 -	// It must have been added in the interim.  Hence it had to have been
  1.2395 -	// separately allocated.  Deallocate the old copy, since we just
  1.2396 -	// replaced it.
  1.2397 -	_STLP_STD::_Destroy(__old_c_string, __old_c_string + __s + 1);
  1.2398 -      _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_tree_ptr, _CharT).deallocate(__old_c_string, __s + 1);
  1.2399 -      }
  1.2400 -#   endif
  1.2401 -    return(__result);
  1.2402 +  if (0 == _M_tree_ptr._M_data) {
  1.2403 +    // Possibly redundant, but probably fast.
  1.2404 +    _S_empty_c_str[0] = _STLP_DEFAULT_CONSTRUCTED(_CharT);
  1.2405 +    return _S_empty_c_str;
  1.2406 +  }
  1.2407 +  _CharT* __old_c_string = _M_tree_ptr._M_data->_M_c_string;
  1.2408 +  if (0 != __old_c_string) return __old_c_string;
  1.2409 +  size_t __s = size();
  1.2410 +  _CharT* __result = _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_tree_ptr, _CharT).allocate(__s + 1);
  1.2411 +  _S_flatten(_M_tree_ptr._M_data, __result);
  1.2412 +  _S_construct_null(__result + __s);
  1.2413 +  __old_c_string = __STATIC_CAST(_CharT*, _Atomic_swap_ptr(__REINTERPRET_CAST(void* _STLP_VOLATILE*, &(_M_tree_ptr._M_data->_M_c_string)),
  1.2414 +                                                           __result));
  1.2415 +  if (0 != __old_c_string) {
  1.2416 +    // It must have been added in the interim.  Hence it had to have been
  1.2417 +    // separately allocated.  Deallocate the old copy, since we just
  1.2418 +    // replaced it.
  1.2419 +    _STLP_STD::_Destroy_Range(__old_c_string, __old_c_string + __s + 1);
  1.2420 +    _STLP_CREATE_ALLOCATOR(allocator_type,(const allocator_type&)_M_tree_ptr, _CharT).deallocate(__old_c_string, __s + 1);
  1.2421 +  }
  1.2422 +  return __result;
  1.2423  }
  1.2424  
  1.2425  template<class _CharT, class _Alloc>
  1.2426  const _CharT* rope<_CharT,_Alloc>::replace_with_c_str() {
  1.2427 -    if (0 == _M_tree_ptr._M_data) {
  1.2428 -        _S_empty_c_str[0] = _S_eos((_CharT*)0);
  1.2429 -        return _S_empty_c_str;
  1.2430 -    }
  1.2431 -    __GC_CONST _CharT* __old_c_string = _M_tree_ptr._M_data->_M_c_string;
  1.2432 -    if (_RopeRep::_S_leaf == _M_tree_ptr._M_data->_M_tag && 0 != __old_c_string) {
  1.2433 -	return(__old_c_string);
  1.2434 -    }
  1.2435 -    size_t __s = size();
  1.2436 -    _CharT* __result = _M_tree_ptr.allocate(_S_rounded_up_size(__s));
  1.2437 -    _S_flatten(_M_tree_ptr._M_data, __result);
  1.2438 -    __result[__s] = _S_eos((_CharT*)0);
  1.2439 -    _M_tree_ptr._M_data->_M_unref_nonnil();
  1.2440 -    _M_tree_ptr._M_data = _S_new_RopeLeaf(__result, __s, get_allocator());
  1.2441 -    return(__result);
  1.2442 +  if (0 == _M_tree_ptr._M_data) {
  1.2443 +    _S_empty_c_str[0] = _STLP_DEFAULT_CONSTRUCTED(_CharT);
  1.2444 +    return _S_empty_c_str;
  1.2445 +  }
  1.2446 +  _CharT* __old_c_string = _M_tree_ptr._M_data->_M_c_string;
  1.2447 +  if (_RopeRep::_S_leaf == _M_tree_ptr._M_data->_M_tag && 0 != __old_c_string) {
  1.2448 +    return __old_c_string;
  1.2449 +  }
  1.2450 +  size_t __s = size();
  1.2451 +  _CharT* __result = _M_tree_ptr.allocate(_S_rounded_up_size(__s));
  1.2452 +  _S_flatten(_M_tree_ptr._M_data, __result);
  1.2453 +  _S_construct_null(__result + __s);
  1.2454 +  _M_tree_ptr._M_data->_M_unref_nonnil();
  1.2455 +  _M_tree_ptr._M_data = _S_new_RopeLeaf(__result, __s, _M_tree_ptr);
  1.2456 +  return __result;
  1.2457  }
  1.2458  
  1.2459  // Algorithm specializations.  More should be added.
  1.2460  
  1.2461 -#ifndef _STLP_MSVC
  1.2462 +#if (!defined (_STLP_MSVC) || (_STLP_MSVC >= 1310)) && \
  1.2463 +    (!defined (__DMC__) || defined (__PUT_STATIC_DATA_MEMBERS_HERE))
  1.2464  // I couldn't get this to work with VC++
  1.2465  template<class _CharT,class _Alloc>
  1.2466 -void
  1.2467 -_Rope_rotate(_Rope_iterator<_CharT,_Alloc> __first,
  1.2468 -              _Rope_iterator<_CharT,_Alloc> __middle,
  1.2469 -              _Rope_iterator<_CharT,_Alloc> __last)
  1.2470 -{
  1.2471 -    _STLP_ASSERT(__first.container() == __middle.container()
  1.2472 -                 && __middle.container() == __last.container())
  1.2473 -    rope<_CharT,_Alloc>& __r(__first.container());
  1.2474 -    rope<_CharT,_Alloc> __prefix = __r.substr(0, __first.index());
  1.2475 -    rope<_CharT,_Alloc> __suffix = 
  1.2476 -      __r.substr(__last.index(), __r.size() - __last.index());
  1.2477 -    rope<_CharT,_Alloc> __part1 = 
  1.2478 -      __r.substr(__middle.index(), __last.index() - __middle.index());
  1.2479 -    rope<_CharT,_Alloc> __part2 = 
  1.2480 -      __r.substr(__first.index(), __middle.index() - __first.index());
  1.2481 -    __r = __prefix;
  1.2482 -    __r += __part1;
  1.2483 -    __r += __part2;
  1.2484 -    __r += __suffix;
  1.2485 +void _Rope_rotate(_Rope_iterator<_CharT,_Alloc> __first,
  1.2486 +                  _Rope_iterator<_CharT,_Alloc> __middle,
  1.2487 +                  _Rope_iterator<_CharT,_Alloc> __last) {
  1.2488 +  _STLP_ASSERT(__first.container() == __middle.container() &&
  1.2489 +               __middle.container() == __last.container())
  1.2490 +  rope<_CharT,_Alloc>& __r(__first.container());
  1.2491 +  rope<_CharT,_Alloc> __prefix = __r.substr(0, __first.index());
  1.2492 +  rope<_CharT,_Alloc> __suffix =
  1.2493 +    __r.substr(__last.index(), __r.size() - __last.index());
  1.2494 +  rope<_CharT,_Alloc> __part1 =
  1.2495 +    __r.substr(__middle.index(), __last.index() - __middle.index());
  1.2496 +  rope<_CharT,_Alloc> __part2 =
  1.2497 +    __r.substr(__first.index(), __middle.index() - __first.index());
  1.2498 +  __r = __prefix;
  1.2499 +  __r += __part1;
  1.2500 +  __r += __part2;
  1.2501 +  __r += __suffix;
  1.2502  }
  1.2503  
  1.2504  
  1.2505 @@ -1522,7 +1410,7 @@
  1.2506  //   for unicode strings.  Unsigned short may be a better character
  1.2507  //   type.
  1.2508  inline void rotate(
  1.2509 -		_Rope_iterator<wchar_t,_STLP_DEFAULT_ALLOCATOR(char) > __first,
  1.2510 +    _Rope_iterator<wchar_t,_STLP_DEFAULT_ALLOCATOR(char) > __first,
  1.2511                  _Rope_iterator<wchar_t,_STLP_DEFAULT_ALLOCATOR(char) > __middle,
  1.2512                  _Rope_iterator<wchar_t,_STLP_DEFAULT_ALLOCATOR(char) > __last) {
  1.2513      _Rope_rotate(__first, __middle, __last);
  1.2514 @@ -1530,10 +1418,10 @@
  1.2515  # endif
  1.2516  #endif /* _STLP_MSVC */
  1.2517  
  1.2518 -#   undef __RopeLeaf__ 
  1.2519 -#   undef __RopeRep__ 
  1.2520 -#   undef __RopeLeaf 
  1.2521 -#   undef __RopeRep 
  1.2522 +#   undef __RopeLeaf__
  1.2523 +#   undef __RopeRep__
  1.2524 +#   undef __RopeLeaf
  1.2525 +#   undef __RopeRep
  1.2526  #   undef size_type
  1.2527  
  1.2528  _STLP_END_NAMESPACE