HomeClusterLabs Projects
Diffusion Booth f3a2cfefcaf4

Refactor: Rewrite list_ticket to use GString for building strings.

Description

Refactor: Rewrite list_ticket to use GString for building strings.

  • Skip all the counting at the beginning to decide how much memory to allocate, and instead allocate a string that should typically be large enough. However, GStrings can grow dynamically so it's not critical we get this completely correct.
  • Remove all the snprintf calls that have to keep track of how much they've already allocated. Instead, use g_string_append_printf or g_string_append as appropriate.
  • Simplify the pending_str block. Use asprintf to build up this string since we have to pass a static buffer to strftime. Then if we ever created a pending string, append and free it later.
  • Simplify the multiple_grant_warning_length check to not use a prefix decrement operator. We can just compare it to the number we actually care about instead.
  • Return a char * and free the GString internally so callers don't have to care about the implementation, and don't also return the length of the string. Callers can check that when they need to know it.

Details

Provenance
clumensAuthored on Sep 4 2024, 11:59 AM
Parents
rB55e67e7fd7d8: Refactor: Unindent various code blocks.
Branches
Unknown
Tags
Unknown

Event Timeline