[libcxx-commits] [PATCH] D115598: [libc++][NFC] Remove goto from std::string

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 12 05:34:46 PST 2021


philnik created this revision.
philnik added reviewers: Quuxplusone, ldionne.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Remove `goto` from `std::string`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115598

Files:
  libcxx/include/string


Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -1694,6 +1694,15 @@
       return *this;
     }
 
+    void __finish_replace(size_type& __sz, size_type& __n1, size_type& __n2, value_type*& __p) {
+      // __sz += __n2 - __n1; in this and the below function below can cause unsigned
+      // integer overflow, but this is a safe operation, so we disable the check.
+      __sz += __n2 - __n1;
+      __set_size(__sz);
+      __invalidate_iterators_past(__sz);
+      traits_type::assign(__p[__sz], value_type());
+    }
+
     _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
     _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
 
@@ -2996,7 +3005,8 @@
                 {
                     traits_type::move(__p + __pos, __s, __n2);
                     traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
-                    goto __finish;
+                    __finish_replace(__sz, __n1, __n2, __p);
+                    return *this;
                 }
                 if (__p + __pos < __s && __s < __p + __sz)
                 {
@@ -3015,13 +3025,7 @@
             }
         }
         traits_type::move(__p + __pos, __s, __n2);
-__finish:
-// __sz += __n2 - __n1; in this and the below function below can cause unsigned
-// integer overflow, but this is a safe operation, so we disable the check.
-        __sz += __n2 - __n1;
-        __set_size(__sz);
-        __invalidate_iterators_past(__sz);
-        traits_type::assign(__p[__sz], value_type());
+        __finish_replace(__sz, __n1, __n2, __p);
     }
     else
         __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115598.393747.patch
Type: text/x-patch
Size: 1787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211212/c3bfa417/attachment.bin>


More information about the libcxx-commits mailing list