Skip to content

Commit a8630e9

Browse files
committed
Add GC check to Array.append()
1 parent 245c3d1 commit a8630e9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/array.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Array
112112
removed
113113
}
114114

115-
pub fn extend(&mut self, other: &Array, alloc: &mut Alloc) -> Result<(), ()> {
115+
pub fn append(&mut self, other: &Array, alloc: &mut Alloc) -> Result<(), ()> {
116116
let other_elems = other.items();
117117
let cur_len = self.len();
118118

@@ -206,7 +206,19 @@ pub fn array_insert(actor: &mut Actor, mut array: Value, mut idx: Value, mut val
206206

207207
pub fn array_append(actor: &mut Actor, mut self_array: Value, mut other_array: Value) -> Result<Value, String>
208208
{
209-
let other_elems = other_array.unwrap_arr();
210-
self_array.unwrap_arr().extend(other_elems, &mut actor.alloc).unwrap();
209+
let a0 = self_array.unwrap_arr();
210+
let a1 = other_array.unwrap_arr();
211+
let new_len = a0.len() + a1.len();
212+
213+
if a0.len() + a1.len() > a0.capacity() {
214+
actor.gc_check(
215+
size_of::<Value>() * new_len,
216+
&mut [&mut self_array, &mut other_array]
217+
)
218+
}
219+
220+
let a0 = self_array.unwrap_arr();
221+
let a1 = other_array.unwrap_arr();
222+
a0.append(a1, &mut actor.alloc).unwrap();
211223
Ok(Value::Nil)
212224
}

0 commit comments

Comments
 (0)