add eina_stringshare_refplace(): same as replace(), but calls ref instead of add
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 1 Feb 2013 11:12:33 +0000 (11:12 +0000)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 1 Feb 2013 11:12:33 +0000 (11:12 +0000)
also fixed a small doc error

SVN revision: 83549

ChangeLog
NEWS
src/lib/eina/eina_inline_stringshare.x

index d7af9dc..1afed9b 100644 (file)
--- 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 ecbec79..925acd2 100644 (file)
--- 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()
index 22fa2ef..9491c83 100644 (file)
  */
 
 /**
+ * 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.
  *