From 1f9a84b9ccddf542d13c7a601f68ff737b48a1f0 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 1 Feb 2013 11:12:33 +0000 Subject: [PATCH] add eina_stringshare_refplace(): same as replace(), but calls ref instead of add also fixed a small doc error SVN revision: 83549 --- ChangeLog | 1 + NEWS | 1 + src/lib/eina/eina_inline_stringshare.x | 36 ++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d7af9dcf93..1afed9b6df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2013-02-01 Mike Blumenkrantz * added eet_data_descriptor_name_get() + * added eina_stringshare_refplace() 2013-01-31 Guillaume Friloux diff --git a/NEWS b/NEWS index ecbec790a9..925acd2eb4 100644 --- a/NEWS +++ b/NEWS @@ -48,6 +48,7 @@ Additions: * Added eina_xattr_fd_get(), eina_xattr_fd_set(), eina_xattr_del(), eina_xattr_fd_del(), eina_xattr_copy() and eina_xattr_fd_copy() + * added eina_stringshare_refplace() * Added eina_file_copy() * Add eet_mmap. * added eet_data_descriptor_name_get() diff --git a/src/lib/eina/eina_inline_stringshare.x b/src/lib/eina/eina_inline_stringshare.x index 22fa2ef5b7..9491c83615 100644 --- a/src/lib/eina/eina_inline_stringshare.x +++ b/src/lib/eina/eina_inline_stringshare.x @@ -27,10 +27,42 @@ * @{ */ +/** + * Replace the previously stringshared pointer with another stringshared pointer. + * + * The string pointed by @a p_str must be previously stringshared or + * @c NULL and it will be eina_stringshare_del(). The new string must also + * be stringshared and will be passed to eina_stringshare_ref() and then assigned to @c *p_str. + * This function is identical to eina_stringshare_replace() except that it calls + * eina_stringshare_ref() instead of eina_stringshare_del() + * + * @param p_str pointer to the stringhare to be replaced. Must not be + * @c NULL, but @c *p_str may be @c NULL as it is a valid + * stringshare handle. + * @param news new string to replace with, may be @c NULL. + * + * @return #EINA_TRUE if the strings were different and thus replaced, #EINA_FALSE + * if the strings were the same after shared. + * + * @since 1.8 + */ +static inline Eina_Bool +eina_stringshare_refplace(Eina_Stringshare **p_str, Eina_Stringshare *news) +{ + if (*p_str == news) return EINA_FALSE; + + news = eina_stringshare_ref(news); + eina_stringshare_del(*p_str); + if (*p_str == news) + return EINA_FALSE; + *p_str = news; + return EINA_TRUE; +} + /** * Replace the previously stringshared pointer with new content. * - * The string pointed by @a p_str should be previously stringshared or + * The string pointed by @a p_str must be previously stringshared or * @c NULL and it will be eina_stringshare_del(). The new string will * be passed to eina_stringshare_add() and then assigned to @c *p_str. * @@ -58,7 +90,7 @@ eina_stringshare_replace(Eina_Stringshare **p_str, const char *news) /** * Replace the previously stringshared pointer with a new content. * - * The string pointed by @a p_str should be previously stringshared or + * The string pointed by @a p_str must be previously stringshared or * @c NULL and it will be eina_stringshare_del(). The new string will * be passed to eina_stringshare_add_length() and then assigned to @c *p_str. *