[libcxx-commits] [libcxx] [libc++] Ensure strong exception guarantee for forward_list::resize (PR #131025)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 16 01:46:44 PDT 2025


================
@@ -1240,12 +1271,7 @@ void forward_list<_Tp, _Alloc>::resize(size_type __n) {
   if (__i != __e)
     erase_after(__p, __e);
   else {
-    __n -= __sz;
-    if (__n > 0) {
-      for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n, __ptr = __ptr->__next_as_begin()) {
-        __ptr->__next_ = this->__create_node(/* next = */ nullptr);
-      }
-    }
+    __default_insert_after(__p, __n - __sz);
----------------
frederick-vs-ja wrote:

As `__default_insert_after` is only used once, it seems better to me to inline it into `resize`.

https://github.com/llvm/llvm-project/pull/131025


More information about the libcxx-commits mailing list