From: Willy Tarreau Date: Mon, 29 Oct 2012 12:23:11 +0000 (+0100) Subject: MINOR: chunk: add a function to reset a chunk X-Git-Tag: v1.5-dev13~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c26ac9deeabe3af21a90c97b4fd626430d178b0f;p=thirdparty%2Fhaproxy.git MINOR: chunk: add a function to reset a chunk This is a first step in avoiding to constantly reinitialize chunks. It replaces the old chunk_reset() which was not properly named as it used to drop everything and was only used by chunk_destroy(). It has been renamed chunk_drop(). --- diff --git a/include/common/chunk.h b/include/common/chunk.h index 00437d5ddb..e7d6040f2a 100644 --- a/include/common/chunk.h +++ b/include/common/chunk.h @@ -45,6 +45,11 @@ int chunk_asciiencode(struct chunk *dst, struct chunk *src, char qc); int chunk_strcmp(const struct chunk *chk, const char *str); int chunk_strcasecmp(const struct chunk *chk, const char *str); +static inline void chunk_reset(struct chunk *chk) +{ + chk->len = 0; +} + static inline void chunk_init(struct chunk *chk, char *str, size_t size) { chk->str = str; @@ -88,7 +93,7 @@ static inline int chunk_strcpy(struct chunk *chk, const char *str) return 1; } -static inline void chunk_reset(struct chunk *chk) +static inline void chunk_drop(struct chunk *chk) { chk->str = NULL; chk->len = -1; @@ -100,10 +105,8 @@ static inline void chunk_destroy(struct chunk *chk) if (!chk->size) return; - if (chk->str) - free(chk->str); - - chunk_reset(chk); + free(chk->str); + chunk_drop(chk); } /*