[libcxx-commits] [libcxx] [libc++] Optimize using std::copy with an ostreambuf_iterator (PR #181815)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 25 08:13:35 PST 2026


================
@@ -55,27 +55,15 @@ _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_CharT, _Traits> __pad_and_output(
     __ns -= __sz;
   else
     __ns = 0;
-  streamsize __np = __op - __ob;
-  if (__np > 0) {
-    if (__s.__sbuf_->sputn(__ob, __np) != __np) {
-      __s.__sbuf_ = nullptr;
-      return __s;
-    }
-  }
+  __s = std::copy(__ob, __op, __s);
   if (__ns > 0) {
     basic_string<_CharT, _Traits> __sp(__ns, __fl);
     if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns) {
       __s.__sbuf_ = nullptr;
       return __s;
     }
   }
----------------
ldionne wrote:

This could potentially be refactored with https://github.com/llvm/llvm-project/issues/183321.

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


More information about the libcxx-commits mailing list