[libcxx-commits] [PATCH] D123058: [libc++] Add capacity constructor to string

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 5 04:22:16 PDT 2022


philnik updated this revision to Diff 420449.
philnik marked an inline comment as done.
philnik added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123058/new/

https://reviews.llvm.org/D123058

Files:
  libcxx/include/string


Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -4165,10 +4165,11 @@
           const basic_string<_CharT, _Traits, _Allocator>& __rhs)
 {
     using _String = basic_string<_CharT, _Traits, _Allocator>;
-    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
     typename _String::size_type __lhs_sz = __lhs.size();
     typename _String::size_type __rhs_sz = __rhs.size();
-    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
+    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
+    __r.reserve(__lhs_sz + __rhs_sz);
+    __r.append(__lhs.data(), __lhs_sz);
     __r.append(__rhs.data(), __rhs_sz);
     return __r;
 }
@@ -4178,10 +4179,11 @@
 operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
 {
     using _String = basic_string<_CharT, _Traits, _Allocator>;
-    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
     typename _String::size_type __lhs_sz = _Traits::length(__lhs);
     typename _String::size_type __rhs_sz = __rhs.size();
-    __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
+    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
+    __r.reserve(__lhs_sz + __rhs_sz);
+    __r.append(__lhs, __lhs_sz);
     __r.append(__rhs.data(), __rhs_sz);
     return __r;
 }
@@ -4191,9 +4193,10 @@
 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
 {
     using _String = basic_string<_CharT, _Traits, _Allocator>;
-    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
     typename _String::size_type __rhs_sz = __rhs.size();
-    __r.__init(&__lhs, 1, 1 + __rhs_sz);
+    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
+    __r.reserve(__rhs_sz + 1);
+    __r.push_back(__lhs);
     __r.append(__rhs.data(), __rhs_sz);
     return __r;
 }
@@ -4204,10 +4207,11 @@
 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
 {
     using _String = basic_string<_CharT, _Traits, _Allocator>;
-    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
     typename _String::size_type __lhs_sz = __lhs.size();
     typename _String::size_type __rhs_sz = _Traits::length(__rhs);
-    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
+    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
+    __r.reserve(__lhs_sz + __rhs_sz);
+    __r.append(__lhs.data(), __lhs_sz);
     __r.append(__rhs, __rhs_sz);
     return __r;
 }
@@ -4217,9 +4221,10 @@
 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
 {
     using _String = basic_string<_CharT, _Traits, _Allocator>;
-    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
     typename _String::size_type __lhs_sz = __lhs.size();
-    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
+    _String __r(_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
+    __r.reserve(__lhs_sz + 1);
+    __r.append(__lhs.data(), __lhs_sz);
     __r.push_back(__rhs);
     return __r;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123058.420449.patch
Type: text/x-patch
Size: 3463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220405/1a6f23db/attachment.bin>


More information about the libcxx-commits mailing list