@@ -108,35 +108,7 @@ class mut_slice_t
108108 }
109109
110110 mut_slice_t & operator =(const slice_t <T>& rhs) {
111- DSPLIB_ASSERT (this ->size () == rhs.size (), " Slices size must be equal" );
112- const int count = this ->size ();
113-
114- // empty slice assign
115- if (count == 0 ) {
116- return *this ;
117- }
118-
119- // simple block copy/move (optimization)
120- const bool is_same = is_same_memory (rhs, slice_t (*this ));
121- if ((this ->stride () == 1 ) && (rhs.stride () == 1 )) {
122- const auto * src = &(*rhs.begin ());
123- auto * dst = &(*begin ());
124- if (!is_same) {
125- std::memcpy (dst, src, count * sizeof (*src));
126- } else {
127- // overlapped
128- std::memmove (dst, src, count * sizeof (*src));
129- }
130- return *this ;
131- }
132-
133- // same array, specific indexing
134- if (is_same) {
135- *this = base_array<T>(rhs);
136- return *this ;
137- }
138-
139- std::copy (rhs.begin (), rhs.end (), this ->begin ());
111+ this ->copy (*this , rhs);
140112 return *this ;
141113 }
142114
@@ -218,6 +190,38 @@ class mut_slice_t
218190 return mut_slice_t (data + i1, step, count);
219191 }
220192
193+ static void copy (mut_slice_t <T> lhs, slice_t <T> rhs) {
194+ DSPLIB_ASSERT (lhs.size () == rhs.size (), " Slices size must be equal" );
195+ const int count = lhs.size ();
196+
197+ // empty slice assign
198+ if (count == 0 ) {
199+ return ;
200+ }
201+
202+ // simple block copy/move (optimization)
203+ const bool is_same = is_same_memory (rhs, slice_t (lhs));
204+ if ((lhs.stride () == 1 ) && (rhs.stride () == 1 )) {
205+ const auto * src = &(*rhs.begin ());
206+ auto * dst = &(*lhs.begin ());
207+ if (!is_same) {
208+ std::memcpy (dst, src, count * sizeof (*src));
209+ } else {
210+ // overlapped
211+ std::memmove (dst, src, count * sizeof (*src));
212+ }
213+ return ;
214+ }
215+
216+ // same array, specific indexing
217+ if (is_same) {
218+ lhs = base_array<T>(rhs);
219+ return ;
220+ }
221+
222+ std::copy (rhs.begin (), rhs.end (), lhs.begin ());
223+ }
224+
221225protected:
222226 explicit mut_slice_t (T* data, int stride, int count)
223227 : data_{data}
0 commit comments