@@ -107,106 +107,6 @@ pub fn[A] Array::unsafe_blit_fixed(
107107 )
108108}
109109
110- ///|
111- /// Copies elements from one array to another array, with support for growing the
112- /// destination array if needed. The arrays may overlap, in which case the copy
113- /// is performed in a way that preserves the data.
114- ///
115- /// Parameters:
116- ///
117- /// * `self` : The array to copy elements from.
118- /// * `dst` : The array to copy elements to. Will be automatically grown
119- /// if needed to accommodate the copied elements.
120- /// * `len` : The number of elements to copy.
121- /// * `src_offset` : Starting index in the source array. Defaults to 0.
122- /// * `dst_offset` : Starting index in the destination array. Defaults to
123- /// 0.
124- ///
125- /// Example:
126- ///
127- /// ```mbt check
128- /// test {
129- /// let src = [1, 2, 3, 4, 5]
130- /// let dst = [0, 0]
131- /// src[:3].blit_to(dst, dst_offset=1)
132- /// @debug.debug_inspect(dst, content="[0, 1, 2, 3]")
133- /// }
134- /// ```
135- ///
136- /// Panics if:
137- ///
138- /// * `len` is negative
139- /// * `src_offset` is negative
140- /// * `dst_offset` is negative
141- /// * `dst_offset` exceeds the length of destination array
142- /// * `src_offset + len` exceeds the length of source array
143- // TODO: make len optional and deprecate it
144- #label_migration (src_offset, fill=false , msg="Use ArrayView ::blit_to instead")
145- #label_migration (len, fill=false , msg="Use ArrayView ::blit_to instead")
146- pub fn [A ] Array ::blit_to(
147- self : Array [A ],
148- dst : Array [A ],
149- len? : Int = self.length(),
150- src_offset? : Int = 0,
151- dst_offset? : Int = 0,
152- ) -> Unit {
153- guard len >= 0 &&
154- dst_offset >= 0 &&
155- src_offset >= 0 &&
156- dst_offset <= dst.length() &&
157- src_offset + len <= self.length()
158- if dst_offset + len > dst.length() {
159- dst.unsafe_grow_to_length(dst_offset + len)
160- }
161- Array ::unsafe_blit(dst, dst_offset, self, src_offset, len)
162- }
163-
164- ///|
165- /// Copies all elements from an array view to a destination array, with support
166- /// for growing the destination array if needed.
167- ///
168- /// Parameters:
169- ///
170- /// * `self` : The array view to copy elements from.
171- /// * `dst` : The array to copy elements to. Will be automatically grown
172- /// if needed to accommodate the copied elements.
173- /// * `dst_offset` : Starting index in the destination array. Defaults to 0.
174- ///
175- /// Example:
176- ///
177- /// ```mbt check
178- /// test {
179- /// let src = [1, 2, 3, 4, 5]
180- /// let view = src[1:4] // view = [2, 3, 4]
181- /// let dst = [0, 0]
182- /// view.blit_to(dst, dst_offset=1)
183- /// @debug.debug_inspect(dst, content="[0, 2, 3, 4]")
184- /// }
185- /// ```
186- ///
187- /// Panics if:
188- ///
189- /// * `dst_offset` is negative
190- /// * `dst_offset` exceeds the length of destination array
191- pub fn [A ] ArrayView ::blit_to(
192- self : ArrayView [A ],
193- dst : Array [A ],
194- dst_offset? : Int = 0,
195- ) -> Unit {
196- let len = self.len()
197- guard dst_offset >= 0 && dst_offset <= dst.length()
198- if dst_offset + len > dst.length() {
199- dst.unsafe_grow_to_length(dst_offset + len)
200- }
201- UninitializedArray ::unsafe_blit(
202- dst.buffer(),
203- dst_offset,
204- self.buf(),
205- self.start(),
206- len,
207- )
208- }
209-
210110///|
211111test " Array::blit_to/basic " {
212112 let src = [1, 2, 3, 4, 5]
@@ -235,6 +135,18 @@ test "Array::blit_to/grow_destination" {
235135 assert_true(dst == [0, 1, 2, 3])
236136}
237137
138+ ///|
139+ #warnings ("-deprecated")
140+ test " Array::blit_to/grow_destination_directly " {
141+ let src = [1, 2, 3, 4]
142+ let dst = [0]
143+ Array ::blit_to(src, dst, len=2, src_offset=1, dst_offset=1)
144+ assert_true(dst == [0, 2, 3])
145+ let self = [1, 2, 3]
146+ Array ::blit_to(self, self, len=2, dst_offset=3)
147+ assert_true(self == [1, 2, 3, 1, 2])
148+ }
149+
238150///|
239151test " Array::blit_to/edge_cases " {
240152 // Test with src_offset and dst_offset
@@ -289,6 +201,14 @@ test "panic Array::blit_to/boundary_cases4" {
289201 ignore(src[0:5].blit_to(dst, dst_offset=6))
290202}
291203
204+ ///|
205+ #warnings ("-deprecated")
206+ test " panic Array::blit_to/reject_overflowed_source_range " {
207+ let src = [1]
208+ let dst = [0]
209+ Array ::blit_to(src, dst, len=0x7fffffff, src_offset=1)
210+ }
211+
292212///|
293213/// TODO
294214/// 1. allow skip
0 commit comments