garray: Rename an internal helper to make its behaviour clearer

`ptr_array_null_terminate()` only `NULL`-terminates the array if its
`null_terminated` flag is set; otherwise it’s a no-op.

Rename the function to `ptr_array_maybe_null_terminate()` to make that a
bit clearer, and make it consistent with `g_ptr_array_maybe_expand()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2022-06-07 13:31:52 +01:00
parent c11e64e7ae
commit d0b0f8f90e

View File

@ -1092,7 +1092,7 @@ static void g_ptr_array_maybe_expand (GRealPtrArray *array,
guint len); guint len);
static void static void
ptr_array_null_terminate (GRealPtrArray *rarray) ptr_array_maybe_null_terminate (GRealPtrArray *rarray)
{ {
if (G_UNLIKELY (rarray->null_terminated)) if (G_UNLIKELY (rarray->null_terminated))
rarray->pdata[rarray->len] = NULL; rarray->pdata[rarray->len] = NULL;
@ -1123,7 +1123,7 @@ ptr_array_new (guint reserved_size,
g_ptr_array_maybe_expand (array, reserved_size); g_ptr_array_maybe_expand (array, reserved_size);
if (null_terminated) if (null_terminated)
{ {
/* don't use ptr_array_null_terminate(). It helps the compiler /* don't use ptr_array_maybe_null_terminate(). It helps the compiler
* to see when @null_terminated is false and thereby inline * to see when @null_terminated is false and thereby inline
* ptr_array_new() and possibly remove the code entirely. */ * ptr_array_new() and possibly remove the code entirely. */
array->pdata[0] = NULL; array->pdata[0] = NULL;
@ -1285,7 +1285,7 @@ g_ptr_array_copy (GPtrArray *array,
new_array->len = array->len; new_array->len = array->len;
} }
ptr_array_null_terminate ((GRealPtrArray *) new_array); ptr_array_maybe_null_terminate ((GRealPtrArray *) new_array);
} }
return new_array; return new_array;
@ -1683,7 +1683,7 @@ g_ptr_array_set_size (GPtrArray *array,
rarray->len = length_unsigned; rarray->len = length_unsigned;
ptr_array_null_terminate (rarray); ptr_array_maybe_null_terminate (rarray);
} }
else if (length_unsigned < rarray->len) else if (length_unsigned < rarray->len)
g_ptr_array_remove_range (array, length_unsigned, rarray->len - length_unsigned); g_ptr_array_remove_range (array, length_unsigned, rarray->len - length_unsigned);
@ -1857,7 +1857,7 @@ g_ptr_array_remove_range (GPtrArray *array,
rarray->pdata[rarray->len + i] = NULL; rarray->pdata[rarray->len + i] = NULL;
} }
else else
ptr_array_null_terminate (rarray); ptr_array_maybe_null_terminate (rarray);
return array; return array;
} }
@ -1958,7 +1958,7 @@ g_ptr_array_add (GPtrArray *array,
rarray->pdata[rarray->len++] = data; rarray->pdata[rarray->len++] = data;
ptr_array_null_terminate (rarray); ptr_array_maybe_null_terminate (rarray);
} }
/** /**
@ -2021,7 +2021,7 @@ g_ptr_array_extend (GPtrArray *array_to_extend,
rarray_to_extend->len += array->len; rarray_to_extend->len += array->len;
ptr_array_null_terminate (rarray_to_extend); ptr_array_maybe_null_terminate (rarray_to_extend);
} }
/** /**
@ -2092,7 +2092,7 @@ g_ptr_array_insert (GPtrArray *array,
rarray->len++; rarray->len++;
rarray->pdata[index_] = data; rarray->pdata[index_] = data;
ptr_array_null_terminate (rarray); ptr_array_maybe_null_terminate (rarray);
} }
/* Please keep this doc-comment in sync with pointer_array_sort_example() /* Please keep this doc-comment in sync with pointer_array_sort_example()