Browse Source

[core] perf: chunkqueue buffers already sized up

provide new interface for sizing to even larger if very large request
(chunkqueue_prepend_buffer_open_sz())
personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
1539cbfdc1
  1. 22
      src/chunk.c
  2. 2
      src/chunk.h

22
src/chunk.c

@ -331,9 +331,18 @@ void chunkqueue_append_chunkqueue(chunkqueue *cq, chunkqueue *src) {
}
buffer * chunkqueue_prepend_buffer_open_sz(chunkqueue *cq, size_t sz) {
chunk * const c = chunkqueue_prepend_mem_chunk(cq);
buffer * const b = c->mem;
if (buffer_string_space(b) < sz) {
buffer_string_prepare_copy(b, ((sz + 4095) & ~4095uL)-1);
}
return b;
}
buffer * chunkqueue_prepend_buffer_open(chunkqueue *cq) {
chunk *c = chunkqueue_prepend_mem_chunk(cq);
buffer_string_prepare_append(c->mem, 4095);
return c->mem;
}
@ -343,9 +352,18 @@ void chunkqueue_prepend_buffer_commit(chunkqueue *cq) {
}
buffer * chunkqueue_append_buffer_open_sz(chunkqueue *cq, size_t sz) {
chunk * const c = chunkqueue_append_mem_chunk(cq);
buffer * const b = c->mem;
if (buffer_string_space(b) < sz) {
buffer_string_prepare_copy(b, ((sz + 4095) & ~4095uL)-1);
}
return b;
}
buffer * chunkqueue_append_buffer_open(chunkqueue *cq) {
chunk *c = chunkqueue_append_mem_chunk(cq);
buffer_string_prepare_append(c->mem, 4095);
return c->mem;
}

2
src/chunk.h

@ -62,8 +62,10 @@ void chunkqueue_append_mem(chunkqueue *cq, const char *mem, size_t len); /* copi
void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */
void chunkqueue_append_chunkqueue(chunkqueue *cq, chunkqueue *src);
buffer * chunkqueue_prepend_buffer_open_sz(chunkqueue *cq, size_t sz);
buffer * chunkqueue_prepend_buffer_open(chunkqueue *cq);
void chunkqueue_prepend_buffer_commit(chunkqueue *cq);
buffer * chunkqueue_append_buffer_open_sz(chunkqueue *cq, size_t sz);
buffer * chunkqueue_append_buffer_open(chunkqueue *cq);
void chunkqueue_append_buffer_commit(chunkqueue *cq);

Loading…
Cancel
Save