Browse Source

[core] perf: buffer_free_ptr() __attribute__ cold

personal/stbuehler/fix-fdevent
Glenn Strauss 3 years ago
parent
commit
babf8112f7
  1. 22
      src/buffer.c

22
src/buffer.c

@ -47,19 +47,21 @@ void buffer_free(buffer *b) {
free(b);
}
void buffer_reset(buffer *b) {
__attribute_cold__
static void buffer_free_ptr(buffer *b) {
if (NULL == b) return;
free(b->ptr);
b->ptr = NULL;
b->used = 0;
b->size = 0;
}
/* limit don't reuse buffer larger than ... bytes */
if (b->size > BUFFER_MAX_REUSE_SIZE) {
free(b->ptr);
b->ptr = NULL;
b->size = 0;
} else if (b->size > 0) {
b->ptr[0] = '\0';
void buffer_reset(buffer *b) {
if (NULL != b && b->size > 0) {
b->used = 0;
/* release buffer larger than ... bytes */
if (b->size > BUFFER_MAX_REUSE_SIZE) buffer_free_ptr(b);
}
b->used = 0;
}
void buffer_move(buffer *b, buffer *src) {

Loading…
Cancel
Save