[libcxx-commits] [PATCH] D102727: Add a compiler option to make string resize/__resize_default_init use precise growth instead of amortized growth.

Evan Brown via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 14 14:49:47 PDT 2021


ezbr updated this revision to Diff 358762.
ezbr added a comment.

Change from adding an option for precise resize to doing so by default and update the change description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102727

Files:
  libcxx/include/string


Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -3276,9 +3276,10 @@
 basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
 {
     size_type __sz = size();
-    if (__n > __sz)
+    if (__n > __sz) {
+        if (__n > capacity()) __shrink_or_extend(__recommend(__n));
         append(__n - __sz, __c);
-    else
+    } else
         __erase_to_end(__n);
 }
 
@@ -3288,6 +3289,7 @@
 {
     size_type __sz = size();
     if (__n > __sz) {
+      if (__n > capacity()) __shrink_or_extend(__recommend(__n));
        __append_default_init(__n - __sz);
     } else
         __erase_to_end(__n);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102727.358762.patch
Type: text/x-patch
Size: 721 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210714/945df9a0/attachment.bin>


More information about the libcxx-commits mailing list