[cfe-commits] [libcxx] r136291 - /libcxx/trunk/include/valarray

Howard Hinnant hhinnant at apple.com
Wed Jul 27 16:19:59 PDT 2011


Author: hhinnant
Date: Wed Jul 27 18:19:59 2011
New Revision: 136291

URL: http://llvm.org/viewvc/llvm-project?rev=136291&view=rev
Log:
Optimizing valarray::operator=(some-valarray-expression)

Modified:
    libcxx/trunk/include/valarray

Modified: libcxx/trunk/include/valarray
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/valarray?rev=136291&r1=136290&r2=136291&view=diff
==============================================================================
--- libcxx/trunk/include/valarray (original)
+++ libcxx/trunk/include/valarray Wed Jul 27 18:19:59 2011
@@ -817,6 +817,8 @@
     valarray& operator=(const gslice_array<value_type>& __ga);
     valarray& operator=(const mask_array<value_type>& __ma);
     valarray& operator=(const indirect_array<value_type>& __ia);
+    template <class _ValExpr>
+        valarray& operator=(const __val_expr<_ValExpr>& __v);
 
     // element access:
     _LIBCPP_INLINE_VISIBILITY
@@ -2959,6 +2961,21 @@
 }
 
 template <class _Tp>
+template <class _ValExpr>
+inline _LIBCPP_INLINE_VISIBILITY
+valarray<_Tp>&
+valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
+{
+    size_t __n = __v.size();
+    if (size() != __n)
+        resize(__n);
+    value_type* __t = __begin_;
+    for (size_t __i = 0; __i != __n; ++__t, ++__i)
+        *__t = result_type(__v[__i]);
+    return *this;
+}
+
+template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 __val_expr<__slice_expr<const valarray<_Tp>&> >
 valarray<_Tp>::operator[](slice __s) const





More information about the cfe-commits mailing list