Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: include/string

Issue 2574553002: [counting-allocator] macOS buildtools/third_party/libc++/trunk/ changes.
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/set ('k') | include/unordered_map » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // -*- C++ -*- 1 // -*- C++ -*-
2 //===--------------------------- string -----------------------------------===// 2 //===--------------------------- string -----------------------------------===//
3 // 3 //
4 // The LLVM Compiler Infrastructure 4 // The LLVM Compiler Infrastructure
5 // 5 //
6 // This file is distributed under the University of Illinois Open Source 6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details. 7 // License. See LICENSE.TXT for details.
8 // 8 //
9 //===----------------------------------------------------------------------===// 9 //===----------------------------------------------------------------------===//
10 10
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 1316
1317 enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; 1317 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
1318 1318
1319 struct __raw 1319 struct __raw
1320 { 1320 {
1321 size_type __words[__n_words]; 1321 size_type __words[__n_words];
1322 }; 1322 };
1323 1323
1324 struct __rep 1324 struct __rep
1325 { 1325 {
1326 __rep(): __s() {}
1326 union 1327 union
1327 { 1328 {
1328 __long __l; 1329 __long __l;
1329 __short __s; 1330 __short __s;
1330 __raw __r; 1331 __raw __r;
1331 }; 1332 };
1332 }; 1333 };
1333 1334
1334 __compressed_pair<__rep, allocator_type> __r_; 1335 __compressed_pair<__rep, allocator_type> __r_;
1335 1336
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 # endif 1752 # endif
1752 1753
1753 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 1754 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1754 1755
1755 _LIBCPP_INLINE_VISIBILITY 1756 _LIBCPP_INLINE_VISIBILITY
1756 void __set_long_size(size_type __s) _NOEXCEPT 1757 void __set_long_size(size_type __s) _NOEXCEPT
1757 {__r_.first().__l.__size_ = __s;} 1758 {__r_.first().__l.__size_ = __s;}
1758 _LIBCPP_INLINE_VISIBILITY 1759 _LIBCPP_INLINE_VISIBILITY
1759 size_type __get_long_size() const _NOEXCEPT 1760 size_type __get_long_size() const _NOEXCEPT
1760 {return __r_.first().__l.__size_;} 1761 {return __r_.first().__l.__size_;}
1762
1761 _LIBCPP_INLINE_VISIBILITY 1763 _LIBCPP_INLINE_VISIBILITY
1762 void __set_size(size_type __s) _NOEXCEPT 1764 void __set_size(size_type __s) _NOEXCEPT
1763 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} 1765 {
1766 if (__is_long())
1767 {
1768 __count_destroyed(__alloc(), __get_long_size());
1769 __count_constructed(__alloc(), __s);
1770 __set_long_size(__s);
1771 }
1772 else
1773 {
1774 __set_short_size(__s);
1775 }
1776 }
1764 1777
1765 _LIBCPP_INLINE_VISIBILITY 1778 _LIBCPP_INLINE_VISIBILITY
1766 void __set_long_cap(size_type __s) _NOEXCEPT 1779 void __set_long_cap(size_type __s) _NOEXCEPT
1767 {__r_.first().__l.__cap_ = __long_mask | __s;} 1780 {__r_.first().__l.__cap_ = __long_mask | __s;}
1768 _LIBCPP_INLINE_VISIBILITY 1781 _LIBCPP_INLINE_VISIBILITY
1769 size_type __get_long_cap() const _NOEXCEPT 1782 size_type __get_long_cap() const _NOEXCEPT
1770 {return __r_.first().__l.__cap_ & size_type(~__long_mask);} 1783 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1771 1784
1772 _LIBCPP_INLINE_VISIBILITY 1785 _LIBCPP_INLINE_VISIBILITY
1786 void __set_long_cap_size(size_type __c, size_type __s) _NOEXCEPT
1787 {
1788 if (__is_long())
1789 {
1790 __count_destroyed(__alloc(), __get_long_size());
1791 }
1792 __set_long_cap(__c);
1793 __set_long_size(__s);
1794 __count_constructed(__alloc(), __s);
1795 }
1796
1797 _LIBCPP_INLINE_VISIBILITY
1773 void __set_long_pointer(pointer __p) _NOEXCEPT 1798 void __set_long_pointer(pointer __p) _NOEXCEPT
1774 {__r_.first().__l.__data_ = __p;} 1799 {__r_.first().__l.__data_ = __p;}
1775 _LIBCPP_INLINE_VISIBILITY 1800 _LIBCPP_INLINE_VISIBILITY
1776 pointer __get_long_pointer() _NOEXCEPT 1801 pointer __get_long_pointer() _NOEXCEPT
1777 {return __r_.first().__l.__data_;} 1802 {return __r_.first().__l.__data_;}
1778 _LIBCPP_INLINE_VISIBILITY 1803 _LIBCPP_INLINE_VISIBILITY
1779 const_pointer __get_long_pointer() const _NOEXCEPT 1804 const_pointer __get_long_pointer() const _NOEXCEPT
1780 {return __r_.first().__l.__data_;} 1805 {return __r_.first().__l.__data_;}
1781 _LIBCPP_INLINE_VISIBILITY 1806 _LIBCPP_INLINE_VISIBILITY
1782 pointer __get_short_pointer() _NOEXCEPT 1807 pointer __get_short_pointer() _NOEXCEPT
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 if (__reserve < __min_cap) 2006 if (__reserve < __min_cap)
1982 { 2007 {
1983 __set_short_size(__sz); 2008 __set_short_size(__sz);
1984 __p = __get_short_pointer(); 2009 __p = __get_short_pointer();
1985 } 2010 }
1986 else 2011 else
1987 { 2012 {
1988 size_type __cap = __recommend(__reserve); 2013 size_type __cap = __recommend(__reserve);
1989 __p = __alloc_traits::allocate(__alloc(), __cap+1); 2014 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1990 __set_long_pointer(__p); 2015 __set_long_pointer(__p);
1991 __set_long_cap(__cap+1); 2016 __set_long_cap_size(__cap+1, __sz);
1992 __set_long_size(__sz);
1993 } 2017 }
1994 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); 2018 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1995 traits_type::assign(__p[__sz], value_type()); 2019 traits_type::assign(__p[__sz], value_type());
1996 } 2020 }
1997 2021
1998 template <class _CharT, class _Traits, class _Allocator> 2022 template <class _CharT, class _Traits, class _Allocator>
1999 void 2023 void
2000 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty pe __sz) 2024 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty pe __sz)
2001 { 2025 {
2002 if (__sz > max_size()) 2026 if (__sz > max_size())
2003 this->__throw_length_error(); 2027 this->__throw_length_error();
2004 pointer __p; 2028 pointer __p;
2005 if (__sz < __min_cap) 2029 if (__sz < __min_cap)
2006 { 2030 {
2007 __set_short_size(__sz); 2031 __set_short_size(__sz);
2008 __p = __get_short_pointer(); 2032 __p = __get_short_pointer();
2009 } 2033 }
2010 else 2034 else
2011 { 2035 {
2012 size_type __cap = __recommend(__sz); 2036 size_type __cap = __recommend(__sz);
2013 __p = __alloc_traits::allocate(__alloc(), __cap+1); 2037 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2014 __set_long_pointer(__p); 2038 __set_long_pointer(__p);
2015 __set_long_cap(__cap+1); 2039 __set_long_cap_size(__cap+1, __sz);
2016 __set_long_size(__sz);
2017 } 2040 }
2018 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); 2041 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
2019 traits_type::assign(__p[__sz], value_type()); 2042 traits_type::assign(__p[__sz], value_type());
2020 } 2043 }
2021 2044
2022 template <class _CharT, class _Traits, class _Allocator> 2045 template <class _CharT, class _Traits, class _Allocator>
2023 inline _LIBCPP_INLINE_VISIBILITY 2046 inline _LIBCPP_INLINE_VISIBILITY
2024 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s) 2047 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
2025 { 2048 {
2026 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr") ; 2049 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr") ;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 if (__n < __min_cap) 2165 if (__n < __min_cap)
2143 { 2166 {
2144 __set_short_size(__n); 2167 __set_short_size(__n);
2145 __p = __get_short_pointer(); 2168 __p = __get_short_pointer();
2146 } 2169 }
2147 else 2170 else
2148 { 2171 {
2149 size_type __cap = __recommend(__n); 2172 size_type __cap = __recommend(__n);
2150 __p = __alloc_traits::allocate(__alloc(), __cap+1); 2173 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2151 __set_long_pointer(__p); 2174 __set_long_pointer(__p);
2152 __set_long_cap(__cap+1); 2175 __set_long_cap_size(__cap+1, __n);
2153 __set_long_size(__n);
2154 } 2176 }
2155 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c); 2177 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
2156 traits_type::assign(__p[__n], value_type()); 2178 traits_type::assign(__p[__n], value_type());
2157 } 2179 }
2158 2180
2159 template <class _CharT, class _Traits, class _Allocator> 2181 template <class _CharT, class _Traits, class _Allocator>
2160 inline _LIBCPP_INLINE_VISIBILITY 2182 inline _LIBCPP_INLINE_VISIBILITY
2161 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_typ e __c) 2183 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_typ e __c)
2162 { 2184 {
2163 __init(__n, __c); 2185 __init(__n, __c);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2205 #ifndef _LIBCPP_NO_EXCEPTIONS 2227 #ifndef _LIBCPP_NO_EXCEPTIONS
2206 try 2228 try
2207 { 2229 {
2208 #endif // _LIBCPP_NO_EXCEPTIONS 2230 #endif // _LIBCPP_NO_EXCEPTIONS
2209 for (; __first != __last; ++__first) 2231 for (; __first != __last; ++__first)
2210 push_back(*__first); 2232 push_back(*__first);
2211 #ifndef _LIBCPP_NO_EXCEPTIONS 2233 #ifndef _LIBCPP_NO_EXCEPTIONS
2212 } 2234 }
2213 catch (...) 2235 catch (...)
2214 { 2236 {
2237 __set_size(0);
2215 if (__is_long()) 2238 if (__is_long())
2216 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_lo ng_cap()); 2239 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_lo ng_cap());
2217 throw; 2240 throw;
2218 } 2241 }
2219 #endif // _LIBCPP_NO_EXCEPTIONS 2242 #endif // _LIBCPP_NO_EXCEPTIONS
2220 } 2243 }
2221 2244
2222 template <class _CharT, class _Traits, class _Allocator> 2245 template <class _CharT, class _Traits, class _Allocator>
2223 template <class _ForwardIterator> 2246 template <class _ForwardIterator>
2224 typename enable_if 2247 typename enable_if
(...skipping 10 matching lines...) Expand all
2235 if (__sz < __min_cap) 2258 if (__sz < __min_cap)
2236 { 2259 {
2237 __set_short_size(__sz); 2260 __set_short_size(__sz);
2238 __p = __get_short_pointer(); 2261 __p = __get_short_pointer();
2239 } 2262 }
2240 else 2263 else
2241 { 2264 {
2242 size_type __cap = __recommend(__sz); 2265 size_type __cap = __recommend(__sz);
2243 __p = __alloc_traits::allocate(__alloc(), __cap+1); 2266 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2244 __set_long_pointer(__p); 2267 __set_long_pointer(__p);
2245 __set_long_cap(__cap+1); 2268 __set_long_cap_size(__cap+1, __sz);
2246 __set_long_size(__sz);
2247 } 2269 }
2248 for (; __first != __last; ++__first, (void) ++__p) 2270 for (; __first != __last; ++__first, (void) ++__p)
2249 traits_type::assign(*__p, *__first); 2271 traits_type::assign(*__p, *__first);
2250 traits_type::assign(*__p, value_type()); 2272 traits_type::assign(*__p, value_type());
2251 } 2273 }
2252 2274
2253 template <class _CharT, class _Traits, class _Allocator> 2275 template <class _CharT, class _Traits, class _Allocator>
2254 template<class _InputIterator> 2276 template<class _InputIterator>
2255 inline _LIBCPP_INLINE_VISIBILITY 2277 inline _LIBCPP_INLINE_VISIBILITY
2256 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) 2278 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 } 2320 }
2299 2321
2300 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2322 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2301 2323
2302 template <class _CharT, class _Traits, class _Allocator> 2324 template <class _CharT, class _Traits, class _Allocator>
2303 basic_string<_CharT, _Traits, _Allocator>::~basic_string() 2325 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2304 { 2326 {
2305 #if _LIBCPP_DEBUG_LEVEL >= 2 2327 #if _LIBCPP_DEBUG_LEVEL >= 2
2306 __get_db()->__erase_c(this); 2328 __get_db()->__erase_c(this);
2307 #endif 2329 #endif
2330 __set_size(0);
2308 if (__is_long()) 2331 if (__is_long())
2309 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_c ap()); 2332 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_c ap());
2310 } 2333 }
2311 2334
2312 template <class _CharT, class _Traits, class _Allocator> 2335 template <class _CharT, class _Traits, class _Allocator>
2313 void 2336 void
2314 basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace 2337 basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2315 (size_type __old_cap, size_type __delta_cap, size_type __old_sz, 2338 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2316 size_type __n_copy, size_type __n_del, size_type __n_add, const value_ type* __p_new_stuff) 2339 size_type __n_copy, size_type __n_del, size_type __n_add, const value_ type* __p_new_stuff)
2317 { 2340 {
(...skipping 11 matching lines...) Expand all
2329 _VSTD::__to_raw_pointer(__old_p), __n_copy); 2352 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2330 if (__n_add != 0) 2353 if (__n_add != 0)
2331 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff , __n_add); 2354 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff , __n_add);
2332 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; 2355 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2333 if (__sec_cp_sz != 0) 2356 if (__sec_cp_sz != 0)
2334 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, 2357 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2335 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz); 2358 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
2336 if (__old_cap+1 != __min_cap) 2359 if (__old_cap+1 != __min_cap)
2337 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); 2360 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2338 __set_long_pointer(__p); 2361 __set_long_pointer(__p);
2339 __set_long_cap(__cap+1);
2340 __old_sz = __n_copy + __n_add + __sec_cp_sz; 2362 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2341 __set_long_size(__old_sz); 2363 __set_long_cap_size(__cap+1, __old_sz);
2342 traits_type::assign(__p[__old_sz], value_type()); 2364 traits_type::assign(__p[__old_sz], value_type());
2343 } 2365 }
2344 2366
2345 template <class _CharT, class _Traits, class _Allocator> 2367 template <class _CharT, class _Traits, class _Allocator>
2346 void 2368 void
2347 basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t ype __delta_cap, size_type __old_sz, 2369 basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t ype __delta_cap, size_type __old_sz,
2348 size_type __n_copy, size_t ype __n_del, size_type __n_add) 2370 size_type __n_copy, size_t ype __n_del, size_type __n_add)
2349 { 2371 {
2350 size_type __ms = max_size(); 2372 size_type __ms = max_size();
2351 if (__delta_cap > __ms - __old_cap) 2373 if (__delta_cap > __ms - __old_cap)
2352 this->__throw_length_error(); 2374 this->__throw_length_error();
2353 pointer __old_p = __get_pointer(); 2375 pointer __old_p = __get_pointer();
2354 size_type __cap = __old_cap < __ms / 2 - __alignment ? 2376 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2355 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __ old_cap)) : 2377 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __ old_cap)) :
2356 __ms - 1; 2378 __ms - 1;
2357 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); 2379 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2358 __invalidate_all_iterators(); 2380 __invalidate_all_iterators();
2359 if (__n_copy != 0) 2381 if (__n_copy != 0)
2360 traits_type::copy(_VSTD::__to_raw_pointer(__p), 2382 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2361 _VSTD::__to_raw_pointer(__old_p), __n_copy); 2383 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2362 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; 2384 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2363 if (__sec_cp_sz != 0) 2385 if (__sec_cp_sz != 0)
2364 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, 2386 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2365 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, 2387 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2366 __sec_cp_sz); 2388 __sec_cp_sz);
2367 if (__old_cap+1 != __min_cap) 2389 if (__old_cap+1 != __min_cap)
2368 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); 2390 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2369 __set_long_pointer(__p); 2391 __set_long_pointer(__p);
2370 __set_long_cap(__cap+1); 2392 __set_long_cap_size(__cap+1, __old_sz);
2371 } 2393 }
2372 2394
2373 // assign 2395 // assign
2374 2396
2375 template <class _CharT, class _Traits, class _Allocator> 2397 template <class _CharT, class _Traits, class _Allocator>
2376 basic_string<_CharT, _Traits, _Allocator>& 2398 basic_string<_CharT, _Traits, _Allocator>&
2377 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_ty pe __n) 2399 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_ty pe __n)
2378 { 2400 {
2379 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr" ); 2401 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr" );
2380 size_type __cap = capacity(); 2402 size_type __cap = capacity();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 } 2436 }
2415 2437
2416 template <class _CharT, class _Traits, class _Allocator> 2438 template <class _CharT, class _Traits, class _Allocator>
2417 basic_string<_CharT, _Traits, _Allocator>& 2439 basic_string<_CharT, _Traits, _Allocator>&
2418 basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) 2440 basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2419 { 2441 {
2420 pointer __p; 2442 pointer __p;
2421 if (__is_long()) 2443 if (__is_long())
2422 { 2444 {
2423 __p = __get_long_pointer(); 2445 __p = __get_long_pointer();
2424 __set_long_size(1);
2425 } 2446 }
2426 else 2447 else
2427 { 2448 {
2428 __p = __get_short_pointer(); 2449 __p = __get_short_pointer();
2429 __set_short_size(1);
2430 } 2450 }
2451 __set_size(1);
2431 traits_type::assign(*__p, __c); 2452 traits_type::assign(*__p, __c);
2432 traits_type::assign(*++__p, value_type()); 2453 traits_type::assign(*++__p, value_type());
2433 __invalidate_iterators_past(1); 2454 __invalidate_iterators_past(1);
2434 return *this; 2455 return *this;
2435 } 2456 }
2436 2457
2437 template <class _CharT, class _Traits, class _Allocator> 2458 template <class _CharT, class _Traits, class _Allocator>
2438 basic_string<_CharT, _Traits, _Allocator>& 2459 basic_string<_CharT, _Traits, _Allocator>&
2439 basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) 2460 basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2440 { 2461 {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2621 } 2642 }
2622 if (__sz == __cap) 2643 if (__sz == __cap)
2623 { 2644 {
2624 __grow_by(__cap, 1, __sz, __sz, 0); 2645 __grow_by(__cap, 1, __sz, __sz, 0);
2625 __is_short = !__is_long(); 2646 __is_short = !__is_long();
2626 } 2647 }
2627 pointer __p; 2648 pointer __p;
2628 if (__is_short) 2649 if (__is_short)
2629 { 2650 {
2630 __p = __get_short_pointer() + __sz; 2651 __p = __get_short_pointer() + __sz;
2631 __set_short_size(__sz+1);
2632 } 2652 }
2633 else 2653 else
2634 { 2654 {
2635 __p = __get_long_pointer() + __sz; 2655 __p = __get_long_pointer() + __sz;
2636 __set_long_size(__sz+1);
2637 } 2656 }
2657 __set_size(__sz+1);
2638 traits_type::assign(*__p, __c); 2658 traits_type::assign(*__p, __c);
2639 traits_type::assign(*++__p, value_type()); 2659 traits_type::assign(*++__p, value_type());
2640 } 2660 }
2641 2661
2642 template <class _CharT, class _Traits, class _Allocator> 2662 template <class _CharT, class _Traits, class _Allocator>
2643 template<class _InputIterator> 2663 template<class _InputIterator>
2644 typename enable_if 2664 typename enable_if
2645 < 2665 <
2646 __is_input_iterator <_InputIterator>::value && 2666 __is_input_iterator <_InputIterator>::value &&
2647 !__is_forward_iterator<_InputIterator>::value, 2667 !__is_forward_iterator<_InputIterator>::value,
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
3145 template <class _CharT, class _Traits, class _Allocator> 3165 template <class _CharT, class _Traits, class _Allocator>
3146 inline _LIBCPP_INLINE_VISIBILITY 3166 inline _LIBCPP_INLINE_VISIBILITY
3147 void 3167 void
3148 basic_string<_CharT, _Traits, _Allocator>::pop_back() 3168 basic_string<_CharT, _Traits, _Allocator>::pop_back()
3149 { 3169 {
3150 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); 3170 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
3151 size_type __sz; 3171 size_type __sz;
3152 if (__is_long()) 3172 if (__is_long())
3153 { 3173 {
3154 __sz = __get_long_size() - 1; 3174 __sz = __get_long_size() - 1;
3155 __set_long_size(__sz);
3156 traits_type::assign(*(__get_long_pointer() + __sz), value_type()); 3175 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3157 } 3176 }
3158 else 3177 else
3159 { 3178 {
3160 __sz = __get_short_size() - 1; 3179 __sz = __get_short_size() - 1;
3161 __set_short_size(__sz);
3162 traits_type::assign(*(__get_short_pointer() + __sz), value_type()); 3180 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3163 } 3181 }
3182 __set_size(__sz);
3164 __invalidate_iterators_past(__sz); 3183 __invalidate_iterators_past(__sz);
3165 } 3184 }
3166 3185
3167 template <class _CharT, class _Traits, class _Allocator> 3186 template <class _CharT, class _Traits, class _Allocator>
3168 inline _LIBCPP_INLINE_VISIBILITY 3187 inline _LIBCPP_INLINE_VISIBILITY
3169 void 3188 void
3170 basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT 3189 basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
3171 { 3190 {
3172 __invalidate_all_iterators(); 3191 __invalidate_all_iterators();
3173 if (__is_long()) 3192 if (__is_long())
3174 { 3193 {
3175 traits_type::assign(*__get_long_pointer(), value_type()); 3194 traits_type::assign(*__get_long_pointer(), value_type());
3176 __set_long_size(0);
3177 } 3195 }
3178 else 3196 else
3179 { 3197 {
3180 traits_type::assign(*__get_short_pointer(), value_type()); 3198 traits_type::assign(*__get_short_pointer(), value_type());
3181 __set_short_size(0);
3182 } 3199 }
3200 __set_size(0);
3183 } 3201 }
3184 3202
3185 template <class _CharT, class _Traits, class _Allocator> 3203 template <class _CharT, class _Traits, class _Allocator>
3186 inline _LIBCPP_INLINE_VISIBILITY 3204 inline _LIBCPP_INLINE_VISIBILITY
3187 void 3205 void
3188 basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) 3206 basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3189 { 3207 {
3190 if (__is_long()) 3208 if (__is_long())
3191 { 3209 {
3192 traits_type::assign(*(__get_long_pointer() + __pos), value_type()); 3210 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3193 __set_long_size(__pos);
3194 } 3211 }
3195 else 3212 else
3196 { 3213 {
3197 traits_type::assign(*(__get_short_pointer() + __pos), value_type()); 3214 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3198 __set_short_size(__pos);
3199 } 3215 }
3216 __set_size(__pos);
3200 __invalidate_iterators_past(__pos); 3217 __invalidate_iterators_past(__pos);
3201 } 3218 }
3202 3219
3203 template <class _CharT, class _Traits, class _Allocator> 3220 template <class _CharT, class _Traits, class _Allocator>
3204 void 3221 void
3205 basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) 3222 basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3206 { 3223 {
3207 size_type __sz = size(); 3224 size_type __sz = size();
3208 if (__n > __sz) 3225 if (__n > __sz)
3209 append(__n - __sz, __c); 3226 append(__n - __sz, __c);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3264 } 3281 }
3265 #else // _LIBCPP_NO_EXCEPTIONS 3282 #else // _LIBCPP_NO_EXCEPTIONS
3266 if (__new_data == nullptr) 3283 if (__new_data == nullptr)
3267 return; 3284 return;
3268 #endif // _LIBCPP_NO_EXCEPTIONS 3285 #endif // _LIBCPP_NO_EXCEPTIONS
3269 } 3286 }
3270 __now_long = true; 3287 __now_long = true;
3271 __was_long = __is_long(); 3288 __was_long = __is_long();
3272 __p = __get_pointer(); 3289 __p = __get_pointer();
3273 } 3290 }
3291 __set_size(0);
3274 traits_type::copy(_VSTD::__to_raw_pointer(__new_data), 3292 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3275 _VSTD::__to_raw_pointer(__p), size()+1); 3293 _VSTD::__to_raw_pointer(__p), __sz+1);
3276 if (__was_long) 3294 if (__was_long)
3277 __alloc_traits::deallocate(__alloc(), __p, __cap+1); 3295 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
3278 if (__now_long) 3296 if (__now_long)
3279 { 3297 {
3280 __set_long_cap(__res_arg+1); 3298 __set_long_cap_size(__res_arg+1, __sz);
3281 __set_long_size(__sz);
3282 __set_long_pointer(__new_data); 3299 __set_long_pointer(__new_data);
3283 } 3300 }
3284 else 3301 else
3285 __set_short_size(__sz); 3302 __set_short_size(__sz);
3286 __invalidate_all_iterators(); 3303 __invalidate_all_iterators();
3287 } 3304 }
3288 } 3305 }
3289 3306
3290 template <class _CharT, class _Traits, class _Allocator> 3307 template <class _CharT, class _Traits, class _Allocator>
3291 inline _LIBCPP_INLINE_VISIBILITY 3308 inline _LIBCPP_INLINE_VISIBILITY
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
4281 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) 4298 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4282 { 4299 {
4283 return basic_string<char32_t> (__str, __len); 4300 return basic_string<char32_t> (__str, __len);
4284 } 4301 }
4285 } 4302 }
4286 } 4303 }
4287 #endif 4304 #endif
4288 4305
4289 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>) 4306 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4290 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>) 4307 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
4291 _LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char > >(char const*, string const&)) 4308 _LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, counting_alloc ator<char, allocation_group::string> >(char const*, string const&))
4292 4309
4293 _LIBCPP_END_NAMESPACE_STD 4310 _LIBCPP_END_NAMESPACE_STD
4294 4311
4295 #endif // _LIBCPP_STRING 4312 #endif // _LIBCPP_STRING
OLDNEW
« no previous file with comments | « include/set ('k') | include/unordered_map » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698