From: Kevin Day Date: Mon, 24 Jan 2022 01:33:55 +0000 (-0600) Subject: Update: Fix incorrect documentation and remove pointless code. X-Git-Tag: 0.5.8~94 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=930600ced416482989ff677a3354a16770fbd30f;p=fll Update: Fix incorrect documentation and remove pointless code. The documentation for some functions do not accurately reflect what the documentation does. This is likely a copy and paste over sight. The f_string_dynamic_resize() is adding one to destination->used. It then updates the used to be that new number minus one. This is pointless. Don't bother with the "total" variable at all. Also use the F_memory_default_allocation_small_d by rather than 1 when resizing. --- diff --git a/level_0/f_string/c/string.h b/level_0/f_string/c/string.h index b474e5e..df7175d 100644 --- a/level_0/f_string/c/string.h +++ b/level_0/f_string/c/string.h @@ -57,7 +57,7 @@ extern "C" { #endif // _di_f_string_append_ /** - * Append the source string onto the destination, but only if the string is not already at the end. + * Append the source string onto the destination only if the string is not already at the end. * * This ignores NULL characters when comparing both the source and the destination. * @@ -82,7 +82,7 @@ extern "C" { #endif // _di_f_string_append_assure_ /** - * Append the source string onto the destination, but only if the string is not already at the end. + * Append the source string onto the destination only if the string is not already at the end. * * This ignores NULL characters when comparing both the source and the destination. * Skips over NULL characters from source when appending. @@ -278,7 +278,7 @@ extern "C" { #endif // _di_f_string_prepend_ /** - * Prepend the source string onto the destination, but only if the string is not already at the beginning. + * Prepend the source string onto the destination only if the string is not already at the beginning. * * Prepend operations require memory move operations and are therefore likely more expensive than append operations. * @@ -305,7 +305,7 @@ extern "C" { #endif // _di_f_string_prepend_assure_ /** - * Prepend the source string onto the destination, but only if the string is not already at the beginning. + * Prepend the source string onto the destination only if the string is not already at the beginning. * * Prepend operations require memory move operations and are therefore likely more expensive than append operations. * diff --git a/level_0/f_string/c/string_dynamic.c b/level_0/f_string/c/string_dynamic.c index c3fd112..401de12 100644 --- a/level_0/f_string/c/string_dynamic.c +++ b/level_0/f_string/c/string_dynamic.c @@ -873,6 +873,7 @@ extern "C" { for (; destination->used; --destination->used) { if (!destination->string[destination->used - 1]) continue; + break; } // for } @@ -881,15 +882,12 @@ extern "C" { return F_status_set_error(F_string_too_large); } - const f_array_length_t total = destination->used + 1; - - if (total > destination->size) { - const f_status_t status = private_f_string_dynamic_resize(total, destination); + if (destination->used + 1 > destination->size) { + const f_status_t status = private_f_string_dynamic_resize(destination->used + F_memory_default_allocation_small_d, destination); if (F_status_is_error(status)) return status; } destination->string[destination->used] = 0; - destination->used = total - 1; return F_none; } diff --git a/level_0/f_string/c/string_dynamic.h b/level_0/f_string/c/string_dynamic.h index 15830c3..db5ea51 100644 --- a/level_0/f_string/c/string_dynamic.h +++ b/level_0/f_string/c/string_dynamic.h @@ -174,7 +174,7 @@ extern "C" { #endif // _di_f_string_dynamic_append_ /** - * Append the source string onto the destination. + * Append the source string onto the destination only if the string is not already at the end. * * @param source * The source string to append. @@ -195,7 +195,7 @@ extern "C" { #endif // _di_f_string_dynamic_append_assure_ /** - * Append the source string onto the destination. + * Append the source string onto the destination only if the string is not already at the end. * * Skips over NULL characters from source when appending. * @@ -452,7 +452,7 @@ extern "C" { #endif // _di_f_string_dynamic_partial_append_ /** - * Append the source string onto the destination, but only if the string is not already at the end and restricted to the given range + * Append the source string onto the destination only if the string is not already at the end and restricted to the given range. * * This ignores NULL characters when comparing both the source and the destination. * @@ -478,7 +478,7 @@ extern "C" { #endif // _di_f_string_dynamic_partial_append_assure_ /** - * Append the source string onto the destination, but only if the string is not already at the end and restricted to the given range + * Append the source string onto the destination only if the string is not already at the end and restricted to the given range. * * This ignores NULL characters when comparing both the source and the destination. * @@ -682,7 +682,7 @@ extern "C" { #endif // _di_f_string_dynamic_partial_prepend_ /** - * Prepend the source string onto the destination, but only if the string is not already at the end and restricted to the given range + * Prepend the source string onto the destination only if the string is not already at the beginning and restricted to the given range. * * Prepend operations require memory move operations and are therefore likely more expensive than append operations. * @@ -710,7 +710,7 @@ extern "C" { #endif // _di_f_string_dynamic_partial_prepend_assure_ /** - * Prepend the source string onto the destination, but only if the string is not already at the end and restricted to the given range + * Prepend the source string onto the destination only if the string is not already at the beginning and restricted to the given range. * * Prepend operations require memory move operations and are therefore likely more expensive than append operations. * @@ -788,7 +788,7 @@ extern "C" { #endif // _di_f_string_dynamic_prepend_ /** - * Prepend the source string onto the destination, but only if the string is not already at the beginning. + * Prepend the source string onto the destination only if the string is not already at the beginning. * * Prepend operations require memory move operations and are therefore likely more expensive than append operations. * @@ -814,7 +814,7 @@ extern "C" { #endif // _di_f_string_dynamic_prepend_assure_ /** - * Prepend the source string onto the destination, but only if the string is not already at the beginning. + * Prepend the source string onto the destination only if the string is not already at the beginning. * * Prepend operations require memory move operations and are therefore likely more expensive than append operations. *