chiark / gitweb /
util: optimize free_and_strdup() if NOP
[elogind.git] / src / shared / util.c
index 275fdece1e70de1d9534179a925d191f8fa1ae5c..b885a46e439fb3a5a197007b4ff90690fa0c074e 100644 (file)
@@ -5683,6 +5683,9 @@ int free_and_strdup(char **p, const char *s) {
         /* Replaces a string pointer with an strdup()ed new string,
          * possibly freeing the old one. */
 
+        if (streq_ptr(*p, s))
+                return 0;
+
         if (s) {
                 t = strdup(s);
                 if (!t)
@@ -5693,7 +5696,7 @@ int free_and_strdup(char **p, const char *s) {
         free(*p);
         *p = t;
 
-        return 0;
+        return 1;
 }
 
 int sethostname_idempotent(const char *s) {