Always use prev node if there's some room in it setDeferredReply (#8729)
this is a followup PR for #8699 instead of copying the deferred reply data to the previous node only if it has room for the entire thing, we can now split the new payload, put part of it into the spare space in the prev node, and the rest may fit into the next node.
This commit is contained in:
parent
1f88ae6212
commit
e40f2219b1
@ -582,13 +582,22 @@ void setDeferredReply(client *c, void *node, const char *s, size_t length) {
|
|||||||
* - It has enough room already allocated
|
* - It has enough room already allocated
|
||||||
* - And not too large (avoid large memmove) */
|
* - And not too large (avoid large memmove) */
|
||||||
if (ln->prev != NULL && (prev = listNodeValue(ln->prev)) &&
|
if (ln->prev != NULL && (prev = listNodeValue(ln->prev)) &&
|
||||||
prev->size - prev->used >= length)
|
prev->size - prev->used > 0)
|
||||||
{
|
{
|
||||||
memcpy(prev->buf + prev->used, s, length);
|
size_t len_to_copy = prev->size - prev->used;
|
||||||
prev->used += length;
|
if (len_to_copy > length)
|
||||||
|
len_to_copy = length;
|
||||||
|
memcpy(prev->buf + prev->used, s, len_to_copy);
|
||||||
|
prev->used += len_to_copy;
|
||||||
|
length -= len_to_copy;
|
||||||
|
if (length == 0) {
|
||||||
listDelNode(c->reply, ln);
|
listDelNode(c->reply, ln);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (ln->next != NULL && (next = listNodeValue(ln->next)) &&
|
s += len_to_copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ln->next != NULL && (next = listNodeValue(ln->next)) &&
|
||||||
next->size - next->used >= length &&
|
next->size - next->used >= length &&
|
||||||
next->used < PROTO_REPLY_CHUNK_BYTES * 4)
|
next->used < PROTO_REPLY_CHUNK_BYTES * 4)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user