Commit 20e49306 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

HTTP/2 HEADERS frame formatting optimistic zero-copy

This avoids memory copying in the most common case that HTTP/2 headers
fit in a single HTT/2 frame.
parent 9bdf3602
......@@ -159,6 +159,18 @@ vlc_h2_frame_headers(uint_fast32_t stream_id, uint_fast32_t mtu, bool eos,
size_t len = hpack_encode(NULL, 0, headers, count);
if (likely(len <= mtu))
{ /* Most common case: single frame - with zero copy */
flags |= VLC_H2_HEADERS_END_HEADERS;
f = vlc_h2_frame_alloc(VLC_H2_FRAME_HEADERS, flags, stream_id, len);
if (unlikely(f == NULL))
return NULL;
hpack_encode(vlc_h2_frame_payload(f), len, headers, count);
return f;
}
/* Edge case: HEADERS frame then CONTINUATION frame(s) */
uint8_t *payload = malloc(len);
if (unlikely(payload == NULL))
......@@ -188,9 +200,6 @@ vlc_h2_frame_headers(uint_fast32_t stream_id, uint_fast32_t mtu, bool eos,
len -= mtu;
}
static_assert(VLC_H2_CONTINUATION_END_HEADERS == VLC_H2_HEADERS_END_HEADERS,
"Oops");
flags |= VLC_H2_CONTINUATION_END_HEADERS;
n = vlc_h2_frame_alloc(type, flags, stream_id, len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment