Skip to content

Commit

Permalink
partial apply
Browse files Browse the repository at this point in the history
  • Loading branch information
serges147 committed Aug 16, 2024
1 parent d19d5b8 commit 6200247
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions libudpard/udpard.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,13 +1081,18 @@ static inline bool rxSlotEject(size_t* const out_payload_size,
{
result = true;
*out_payload_size = eject_ctx.retain_size;
*out_payload_head = (eject_ctx.head != NULL)
? (*eject_ctx.head) // Slice off the derived type fields as they are not needed.
: (struct UdpardFragment){.next = NULL, .view = {0, NULL}, .origin = {0, NULL}};
// This is the single-frame transfer optimization suggested by Scott: we free the first fragment handle
// early by moving the contents into the rx_transfer structure by value.
// No need to free the payload buffer because it has been transferred to the transfer.
memFree(memory.fragment, sizeof(RxFragment), eject_ctx.head); // May be empty.
if (eject_ctx.head != NULL)
{
// This is the single-frame transfer optimization suggested by Scott: we free the first fragment handle
// early by moving the contents into the rx_transfer structure by value.
// No need to free the payload buffer because it has been transferred to the transfer.
*out_payload_head = *eject_ctx.head; // Slice off the derived type fields as they are not needed.
memFree(memory.fragment, sizeof(RxFragment), eject_ctx.head);
}
else
{
*out_payload_head = (struct UdpardFragment){.next = NULL, .view = {0, NULL}, .origin = {0, NULL}};
}
}
else // The transfer turned out to be invalid. We have to free the fragments. Can't use the tree anymore.
{
Expand Down

0 comments on commit 6200247

Please sign in to comment.