[libcxx-commits] [PATCH] D125019: [libc++] Avoid creating temporaries in unary expressions involving valarray

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 5 09:42:19 PDT 2022


philnik added a comment.

Isn't this ABI breaking? Or is it in this case OK for some reason?



================
Comment at: libcxx/include/valarray:926-929
+    __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray&> >   operator+() const;
+    __val_expr<_UnaryOp<negate<_Tp>, const valarray&> >         operator-() const;
+    __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray&> >      operator~() const;
+    __val_expr<_UnaryOp<logical_not<_Tp>, const valarray&> >    operator!() const;
----------------
Add `_LIBCPP_HIDE_FROM_ABI`?


================
Comment at: libcxx/include/valarray:3306
 {
-    valarray<value_type> __r;
-    size_t __n = size();
-    if (__n)
-    {
-        __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
-        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
-            ::new ((void*)__r.__end_) value_type(+*__p);
-    }
-    return __r;
+    typedef _UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&> _Op;
+    return __val_expr<_Op>(_Op(__unary_plus<_Tp>(), *this));
----------------



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125019



More information about the libcxx-commits mailing list