From daa75c69ad00003d5d698a90d30a844b88ab3fae Mon Sep 17 00:00:00 2001 From: barbieri Date: Sat, 27 Feb 2010 15:38:58 +0000 Subject: [PATCH] macro -> inline clear, type checking and same runtime cost. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@46584 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/eina_strbuf.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/lib/eina_strbuf.c b/src/lib/eina_strbuf.c index 2b262f6..a28b9e9 100644 --- a/src/lib/eina_strbuf.c +++ b/src/lib/eina_strbuf.c @@ -43,12 +43,10 @@ struct _Eina_Strbuf }; static Eina_Bool _eina_strbuf_init(Eina_Strbuf *buf); -static Eina_Bool _eina_strbuf_resize(Eina_Strbuf *buf, size_t size); +static inline Eina_Bool _eina_strbuf_grow(Eina_Strbuf *buf, size_t size); +static inline Eina_Bool _eina_strbuf_resize(Eina_Strbuf *buf, size_t size); static inline Eina_Bool _eina_strbuf_insert_length(Eina_Strbuf *buf, const char *str, size_t len, size_t pos); -#define _eina_strbuf_grow(_buf, _size) \ - ((((_size) + 1) > (_buf)->size) ? _eina_strbuf_resize((_buf), (_size)) : EINA_TRUE) - /** * @internal * @brief Initialize the strbuf module. @@ -692,13 +690,31 @@ _eina_strbuf_init(Eina_Strbuf *buf) /** * @internal * + * If required, enlarge the buffer to fit the new size. + * + * @param buf the buffer to resize + * @param size the minimum size of the buffer + * + * @return #EINA_TRUE on success, #EINA_FALSE on failure. + */ +static inline Eina_Bool +_eina_strbuf_grow(Eina_Strbuf *buf, size_t size) +{ + if ((size + 1) < buf->size) + return EINA_TRUE; + return _eina_strbuf_resize(buf, size); +} + +/** + * @internal + * * resize the buffer * @param buf the buffer to resize * @param size the minimum size of the buffer * * @return #EINA_TRUE on success, #EINA_FALSE on failure. */ -static Eina_Bool +static inline Eina_Bool _eina_strbuf_resize(Eina_Strbuf *buf, size_t size) { char *buffer; -- 2.7.4