mirror of
https://github.com/janet-lang/janet
synced 2025-01-15 01:45:41 +00:00
parent
1fba699ed4
commit
2891d2b260
@ -103,12 +103,15 @@ static void janet_fiber_refresh_memory(JanetFiber *fiber) {
|
|||||||
|
|
||||||
/* Ensure that the fiber has enough extra capacity */
|
/* Ensure that the fiber has enough extra capacity */
|
||||||
void janet_fiber_setcapacity(JanetFiber *fiber, int32_t n) {
|
void janet_fiber_setcapacity(JanetFiber *fiber, int32_t n) {
|
||||||
|
int32_t old_size = fiber->capacity;
|
||||||
|
int32_t diff = n - old_size;
|
||||||
Janet *newData = realloc(fiber->data, sizeof(Janet) * n);
|
Janet *newData = realloc(fiber->data, sizeof(Janet) * n);
|
||||||
if (NULL == newData) {
|
if (NULL == newData) {
|
||||||
JANET_OUT_OF_MEMORY;
|
JANET_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
fiber->data = newData;
|
fiber->data = newData;
|
||||||
fiber->capacity = n;
|
fiber->capacity = n;
|
||||||
|
janet_vm_next_collection += sizeof(Janet) * diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grow fiber if needed */
|
/* Grow fiber if needed */
|
||||||
|
Loading…
Reference in New Issue
Block a user