[core] perf: buffer_free_ptr() __attribute__ cold
@@ -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;
-
- /* limit don't reuse buffer larger than ... bytes */
- if (b->size > BUFFER_MAX_REUSE_SIZE) {
free(b->ptr);
b->ptr = NULL;
+ b->used = 0;
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);
+ }
}
void buffer_move(buffer *b, buffer *src) {
