Reallocate arr to new_cap slots, keeping its first n_keep values.
Deliberately written as explicit allocate/copy/deallocate rather than
move_alloc or reallocation-on-assignment: both have historically
been unreliable on nvfortran and LFortran, and this path runs only
O(log n) times over the life of a heap.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(inout), | allocatable | :: | arr(:) | ||
| integer(kind=default_int), | intent(in) | :: | n_keep | |||
| integer(kind=default_int), | intent(in) | :: | new_cap |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | i | ||||
| integer(kind=int64), | private, | allocatable | :: | tmp(:) |
subroutine grow_int64(arr, n_keep, new_cap) !! Reallocate `arr` to `new_cap` slots, keeping its first `n_keep` values. !! !! Deliberately written as explicit allocate/copy/deallocate rather than !! `move_alloc` or reallocation-on-assignment: both have historically !! been unreliable on nvfortran and LFortran, and this path runs only !! O(log n) times over the life of a heap. integer(int64), allocatable, intent(inout) :: arr(:) integer(default_int), intent(in) :: n_keep integer(default_int), intent(in) :: new_cap integer(int64), allocatable :: tmp(:) integer(default_int) :: i if (.not. allocated(arr)) then allocate (arr(new_cap)) return end if allocate (tmp(n_keep)) do i = 1, n_keep tmp(i) = arr(i) end do deallocate (arr) allocate (arr(new_cap)) do i = 1, n_keep arr(i) = tmp(i) end do deallocate (tmp) end subroutine grow_int64