vec_string_append Subroutine

private pure subroutine vec_string_append(self, values, err)

Append many elements, growing once rather than once per element.

Type Bound

vector_string_t

Arguments

Type IntentOptional Attributes Name
class(vector_string_t), intent(inout) :: self
type(string_type), intent(in) :: values(:)
type(error_t), intent(inout), optional :: err

Calls

proc~~vec_string_append~~CallsGraph proc~vec_string_append vector_string_t%vec_string_append proc~error_raise error_raise proc~vec_string_append->proc~error_raise proc~vec_string_capacity vector_string_t%vec_string_capacity proc~vec_string_append->proc~vec_string_capacity proc~vec_string_grow vec_string_grow proc~vec_string_append->proc~vec_string_grow proc~error_set error_t%error_set proc~error_raise->proc~error_set proc~vec_string_grow->proc~error_raise proc~vec_string_grow->proc~vec_string_capacity

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: n_new

Source Code

   pure subroutine vec_string_append(self, values, err)
      !! Append many elements, growing once rather than once per element.
      class(vector_string_t), intent(inout) :: self
      type(string_type), intent(in) :: values(:)
      type(error_t), intent(inout), optional :: err

      integer(default_int) :: n_new

      n_new = size(values, kind=default_int)
      if (n_new == 0) return

      ! Rearranged from `n_items + n_new > MAX` so that the sum is never
      ! formed; the subtraction cannot overflow because `n_items` is
      ! non-negative and PIC_VECTOR_MAX_CAPACITY is `huge`.
      if (n_new > PIC_VECTOR_MAX_CAPACITY - self%n_items) then
         call error_raise(err, ERROR_ALLOC, &
                          "vector_string_t: append would exceed PIC_VECTOR_MAX_CAPACITY.")
         return
      end if

      call vec_string_grow(self, self%n_items + n_new, err)
      if (self%n_items + n_new > vec_string_capacity(self)) return

      self%items(self%n_items + 1:self%n_items + n_new) = values
      self%n_items = self%n_items + n_new
   end subroutine vec_string_append